#!/bin/sh

# I no longer pull winetricks-alpha from winezeug, it's moved to its own repo

# LGPL
# Copyright 2010 Dan Kegel
# Experimental cleanup of winetricks
#
#--------------------------------------------------------------------
# See http://code.google.com/p/winezeug/wiki/ConvergedFrontends
#
# This script, and the verbs it invokes, should follow these Coding standards:
#
# Portability:
# - Portability matters, as this script is run on many operating systems
# - No bash, zsh, or csh extensions; only use features from
#   the Posix standard shell and utilities; see
#   http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
# - Prefer classic sh idioms as described in e.g.
#   "Portable Shell Programming" by Bruce Blinn, ISBN: 0-13-451494-7
# - If there is no universally available program for a needed function,
#   support the two most frequently available programs.
#   e.g. fall back to wget if curl is not available; likewise, support
#   both sha1sum and openssl.
# - When using unix commands like cp, put options before filenames so it will
#   work on systems like MacOSX.  e.g. "rm -f foo.dat", not "rm foo.dat -f"
#
# Formatting:
# - Your terminal and editor must be configured for utf-8
#   If you do not see an o with two dots over it here [ö], stop!
# - Do not use tabs in this file or any verbs.
# - Indent 4 spaces.
# - Try to keep line length below 80 (makes printing easier)
# - Open curly braces ('{') and 'then' at beginning of line,
#   close curlies ('}') and 'fi' should line up with the matching { or if,
#   cases aligned with 'case' and 'esac'.  For instance,
#
#      if test "$FOO" = "bar"
#      then
#         echo "FOO is bar"
#      fi
#      case "$FOO" of
#      bar) echo "FOO is still bar" ;;
#      esac
#
# Commenting:
# - Comments should explain intent in English
# - Keep functions short and well named to reduce need for comments
#
# Naming:
# Public things defined by this script, for use by verbs:
# - Variables have uppercase names starting with W_
# - Functions have lowercase names starting with w_
#
# Private things internal to this script, not for use by verbs:
# - Local variables have lowercase names starting with uppercase _W_
# - Global variables have uppercase names starting with WINETRICKS_
# - Functions have lowercase names starting with winetricks_
# FIXME: A few verbs still use winetricks-private functions or variables.
#
# Internationalization / localization:
# - Important or frequently used message should be internationalized
#   so translations can be easily added.  For example:
#     case $LANG in
#     de*) echo "Das ist die deutsche Meldung" ;;
#     *)   echo "This is the English message" ;;
#     esac
#
#--------------------------------------------------------------------

# Name of this version of winetricks (YYYYMMDD)
WINETRICKS_VERSION=20110117-alpha

#---- Public Functions ----

# Display warning message
w_warn()
{
    echo "------------------------------------------------------"
    echo "$@"
    echo "------------------------------------------------------"

    # For some reason, nulls were showing up in $@?!, causing truncated output
    # in zenity, so use tr to replace NUL chars with spaces.
    msg="`echo $@ | tr '\000' ' '`"
    case $WINETRICKS_GUI in
    zenity) zenity --error --title=winetricks --text="$msg" --no-wrap;;
    kdialog) kdialog --title winetricks --error "$msg" ;;
    none) ;;
    esac
}

# Display fatal error message and terminate script
w_die()
{
    w_warn "$@"

    exit 1
}

# I no longer pull winetricks-alpha from winezeug, it's moved to its own repo
xdg-open http://winetricks.googlecode.com
w_die "winetricks-alpha has moved. Please use the repository http://winetricks.googlecode.com."

# Execute with error checking
# Put this in front of any command that might fail
w_try()
{
    # "VAR=foo w_try cmd" fails to put VAR in the environment
    # with some versions of bash if w_try is a shell function?!
    # This is a problem when trying to pass environment variables to e.g. wine.
    # Adding an explicit export here works around it, so add any we use.
    export WINEDLLOVERRIDES
    echo Executing "$@"

    # On Vista, we need to jump through a few hoops to run commands in cygwin.
    # First, .exe's need to have the executable bit set.
    # Second, only cmd can run setup programs (presumably for security).
    # If $1 ends in .exe, we know we're running on real windows, otherwise
    # $1 would be 'wine'.
    case "$1" in
    *.exe)
        chmod +x "$1" || true # don't care if it fails
        cmd /c "$@"
        ;;
    *)
        "$@"
        ;;
    esac
    status=$?
    if test $status -ne 0
    then
        w_die "Note: command '$@' returned status $status.  Aborting."
    fi
}

w_try_regedit()
{
    # on windows, doesn't work without cmd /c
    case "$OS" in
    "Windows_NT") cmdc="cmd /c";;
    *) unset cmdc ;;
    esac

    w_try winetricks_early_wine $cmdc regedit $W_UNATTENDED_SLASH_S "$@"
}

w_try_regsvr()
{
    w_try $WINE regsvr32 $W_UNATTENDED_SLASH_S $@
}

w_try_cabextract()
{
    # Not always installed, but shouldn't be fatal unless it's being used
    if test ! -x "`which cabextract 2>/dev/null`"
    then
        w_die "Cannot find cabextract.  Please install it (e.g. 'sudo apt-get install cabextract' or 'sudo yum install cabextract')."
    fi

    w_try cabextract -q "$@"
}

w_try_unzip()
{
    # Not always installed, but shouldn't be fatal unless it's being used
    if test ! -x "`which unzip 2>/dev/null`"
    then
        w_die "Cannot find unzip.  Please install it (e.g. 'sudo apt-get install unzip' or 'sudo yum install unzip')."
    fi

    w_try unzip -o -q "$@"
}

w_read_key()
{
    case "$W_OPT_UNATTENDED" in
    0) W_KEY=dummy_to_make_autohotkey_happy ; return 0 ;;
    esac

    _W_keyfile="$W_CACHE/$W_PACKAGE/key.txt"
    if ! test -f "$_W_keyfile"
    then
        # read key from user
        case $LANG in
        da*) _W_keymsg="Angiv venligst registrerings-nøglen for pakken '$_PACKAGE'"
            _W_nokeymsg="Ingen nøgle angivet"
            ;;
        de*) _W_keymsg="Bitte einen Key für Pakete '$W_PACKAGE' eingeben"
            _W_nokeymsg="Keinen Key eingegeben?"
            ;;
        *)  _W_keymsg="Please enter the key for app '$W_PACKAGE'"
            _W_nokeymsg="No key given"
            ;;
        esac
        case $WINETRICKS_GUI in
        *zenity) W_KEY=`zenity --entry --text "$_W_keymsg"` ;;
        *kdialog) W_KEY=`kdialog --inputbox "$_W_keymsg"` ;;
        *xmessage) w_die "sorry, can't read key from gui with xmessage" ;;
        none) echo -n "$_W_keymsg": ; read W_KEY ;;
        esac
        if test "$W_KEY" = ""
        then
            w_die "$_W_nokeymsg"
        fi
        echo "$W_KEY" > "$_W_keyfile"
    fi
    W_KEY=`cat "$_W_keyfile" | tr -d -`
    unset _W_keyfile _W_keymsg _W_nokeymsg
}

# Convert a Unix path to a Windows path
# Usage is lowest common denominator of cygpath/winepath
# so -u to convert to unix, and -w to convert to windows
w_pathconv()
{
    case "$OS" in
     "Windows_NT")
        cygpath "$@"
        ;;
     *)
        winetricks_early_wine winepath "$@"
        ;;
    esac
}

# verify an sha1sum
w_verify_sha1sum()
{
    _W_vs_wantsum=$1
    _W_vs_file=$2

    _W_vs_gotsum=`$WINETRICKS_SHA1SUM < $_W_vs_file | sed 's/ .*//'`
    if [ "$_W_vs_gotsum"x != "$_W_vs_wantsum"x ]
    then
       w_die "sha1sum mismatch!  Rename $_W_vs_file and try again."
    fi
    unset _W_vs_wantsum _W_vs_file _W_vs_gotsum
}

# Execute wget, and if in gui mode, also show a graphical progress bar
winetricks_wget_progress()
{
    case $WINETRICKS_GUI in
    zenity) 
        # Usa a subshell so if the user clicks 'Cancel',
        # the --auto-kill kills the subshell, not the current shell
        (
            wget "$@" 2>&1 |
            sed -u 's/^.* \+\([0-9]\+%\) \+\([0-9.]\+[GMKB]\) \+\([0-9hms.]\+\).*$/\1\n# Downloading... \2 (\3)/' | \
            zenity --progress --width 400 --title="$_W_file" --auto-kill --auto-close
        )
        err=$?
        if test $err -gt 128 
        then
            # 129 is 'killed by SIGHUP'
            # Sadly, --auto-kill only applies to parent process,
            # which was the subshell, not all the elements of the pipeline...
            # have to go find and kill the wget.
            # If we ran wget in the background, we could kill it more directly, perhaps...
            if pid=`ps augxw | grep ."$_W_file" | grep -v grep | awk '{print $2}'`
            then
                echo User aborted download, killing wget
                kill $pid
            fi
        fi
        return $err
        ;;
    *) wget "$@" ;;
    esac
}

# Download a file
# Usage: w_download packagename url [sha1sum [filename [cookie jar]]]
# Caches downloads in winetrickscache/$packagename
w_download()
{
    _W_packagename="$1"
    _W_url="$2"
    _W_sum="$3"
    _W_file="$4"
    _W_cookiejar="$5"

    case $_W_packagename in
    .) w_die "bug: please do not download packages to top of cache" ;;
    esac

    if [ "$_W_file"x = ""x ]
    then
        _W_file=`basename "$_W_url"`
    fi
    _W_cache="$W_CACHE/$_W_packagename"
    mkdir -p "$_W_cache"

    # Try download twice
    checksum_ok=""
    tries=0
    while test $tries -lt 2
    do
        tries=`expr $tries + 1`

        if test -s "$_W_cache/$_W_file" 
        then
            if test "$3"
            then
                if test $tries = 1
                then
                    # The cache was full.  If the file is larger than 500MB,
                    # don't checksum it, that just annoys the user.
                    if test `du -k "$_W_cache/$_W_file" | cut -f1` -gt 500000
                    then
                        checksum_ok=1
                        break
                    fi
                fi
                # If checksum matches, declare success and exit loop
                gotsum=`$WINETRICKS_SHA1SUM < "$_W_cache/$_W_file" | sed 's/(stdin)= //;s/ .*//'`
                if [ "$gotsum"x = "$3"x ]
                then
                    checksum_ok=1
                    break
                fi
                if test ! "$WINETRICKS_CONTINUE_DOWNLOAD"
                then
                    w_warn "Checksum for $_W_cache/$_W_file did not match, retrying download"
                    mv -f "$_W_cache/$_W_file" "$_W_cache/$_W_file".bak
                fi
            else
                # file exists, no checksum known, declare success and exit loop
                break
            fi
        elif test -f "$_W_cache/$_W_file"
        then
            # zero length file, just delete before retrying
            rm "$_W_cache/$_W_file"
        fi

        _W_dl_olddir=`pwd`
        cd "$_W_cache"
        # Mac folks tend to have curl rather than wget
        # On Mac, 'which' doesn't return good exit status
        # Need to jam in --header "Accept-Encoding: gzip,deflate" else
        # redhat.com decompresses liberation-fonts.tar.gz!
        # Note: this causes other sites to compress downloads, hence
        # the kludge further down.  See http://code.google.com/p/winezeug/issues/detail?id=77
        echo Downloading $_W_url
        if [ -x "`which wget 2>/dev/null`" ]
        then
           # Use -nd to insulate ourselves from people who set -x in WGETRC
           # [*] --retry-connrefused works around the broken sf.net mirroring
           # system when downloading corefonts
           # [*] --read-timeout is useful on the adobe server that doesn't
           # close the connection unless you tell it to (control-C or closing
           # the socket)
           # Disable retries for gog.com (which requires higher level retries)
           winetricks_wget_progress -O "$_W_file" -nd -c --read-timeout=300 --tries=1 --retry-connrefused --header "Accept-Encoding: gzip,deflate" ${_W_cookiejar:+--load-cookies "$_W_cookiejar"} "$_W_url"
        else
           # curl doesn't get filename from the location given by the server!
           # fortunately, we know it
           curl -L -o "$_W_file" -C - --header "Accept-Encoding: gzip,deflate" ${_W_cookiejar:+--cookie "$_W_cookiejar"} "$_W_url"
        fi
        if test $? != 0
        then
            test -f "$_W_file" && rm "$_W_file"
            w_die "Downloading $_W_url failed"
        fi
        # Need to decompress .exe's that are compressed, else cygwin fails
        # Only affects cygwin, so don't barf if 'file' not installed
        _W_filetype=`which file 2>/dev/null`
        case $_W_filetype-$_W_file in
        /*-*.exe)
            case `file "$_W_file"` in
            *gzip*) mv "$_W_file" "$_W_file.gz"; gunzip < "$_W_file.gz" > "$_W_file";;
            esac
        esac

        # On cygwin, .exe's must be marked +x
        case "$_W_file" in
        *.exe) chmod +x "$_W_file" ;;
        esac

        cd "$_W_dl_olddir"
        unset _W_dl_olddir
    done

    if test "$3" -a ! "$checksum_ok"
    then 
        w_verify_sha1sum $3  "$_W_cache/$_W_file"
    fi
}

# Download one or more files via bittorrent
# Usage: w_download_torrent package [foo.torrent]
# Caches downloads in $W_CACHE/$package, torrent files are assumed to be there
# If no foo.torrent is given, will add ALL .torrent files in $W_CACHE/$W_PACKAGE
w_download_torrent()
{
    # FIXME: figure out how to extract the filename from the .torrent file
    # so callers don't need to check if the files are already downloaded.

    w_call utorrent

    UT_WINPATH="$W_CACHE_WIN\\$1"
    cd "$W_CACHE/$1"

    if [ "$2"x != ""x ] # foo.torrent parameter supplied
    then
        w_try $WINE utorrent "/DIRECTORY" "$UT_WINPATH" "$UT_WINPATH\\$2" &
    else # grab all torrents
        for torrent in `ls *.torrent`
        do
            w_try $WINE utorrent "/DIRECTORY" "$UT_WINPATH" "$UT_WINPATH\\$torrent" &
        done
    fi

    # Start uTorrent, have it wait until all downloads are finished
    w_ahk_do "
        SetTitleMatchMode, 2
        winwait, Torrent
        Loop
        {
            sleep 6000
            ifwinexist, Torrent, default
            {
                ;should uTorrent be the default torrent app?
                controlclick, Button1, Torrent, default  ; yes
                continue
            }
            ifwinexist, Torrent, already
            {
                ;torrent already registered, fine
                controlclick, Button1, Torrent, default  ; yes
                continue
            }
            ifwinexist, Torrent, Bandwidth
            {
                ;Cancels bandwidth test on first run of uTorrent
                controlclick, Button5, Torrent, Bandwidth
                continue
            }
            ifwinexist, Torrent, version
            {
                ;Decline upgrade to newer version
                controlclick, Button3, Torrent, version
                controlclick, Button2, Torrent, version
                continue
            }
            break
        }
        ;Sets parameter to close uTorrent once all downloads are complete
        winactivate, Torrent 2.0
        send !o
        send a{Down}{Enter}
        winwaitclose, Torrent 2.0
    "
}

w_download_manual()
{
    _W_packagename="$1"
    _W_url="$2"
    _W_file="$3"
    _W_sha1sum="$4"

    case $LANG in
    da*) _W_dlmsg="Hent venligst filen $_W_file fra $_W_url og placér den i $W_CACHE/$_W_packagename, kør derefter dette skript.";;
    de*) _W_dlmsg="Bitte laden Sie $_W_file von $_W_url runter, stellen Sie's in $W_CACHE/$_W_packagename, dann wiederholen Sie diesen Kommando.";;
    *) _W_dlmsg="Please download $_W_file from $_W_url, place it in $W_CACHE/$_W_packagename, then re-run this script.";;
    esac

    if ! test -f "$W_CACHE/$_W_packagename/$_W_file"
    then
        mkdir -p "$W_CACHE/$_W_packagename"
        case "$OS" in
        "Windows_NT") cygstart "$_W_url" ;;
        *) xdg-open "$_W_url" ;;
        esac
        sleep 3   # give some time for browser to open
        w_die "$_W_dlmsg"
        # FIXME: wait in loop until file is finished?
    fi
    # FIXME: verify $sha1sum of $file
    unset _W_url _W_file _W_sha1sum _W_dlmsg
}

# Usage: w_mount "volume name"
# FIXME: should take mount option 'unhide' for poorly mastered discs
w_mount()
{
    WINETRICKS_IMG="$W_CACHE/$W_PACKAGE/$1.iso"
    mkdir -p "$W_CACHE/$W_PACKAGE"

    if test -f "$WINETRICKS_IMG"
    then
        winetricks_mount_cached_iso "$1"
    else
        case "$WINETRICKS_OPT_KEEPISOS" in
        0)
            winetricks_mount_real_volume "$1"
            ;;
        1)
            winetricks_cache_iso "$1"
            winetricks_mount_cached_iso "$1"
            ;;
        esac
    fi
}

w_umount()
{
    if test "$WINE" = ""
    then
        w_die Windows not yet supported
    else
        echo "Running $WINETRICKS_SUDO umount $W_ISO_MOUNT_ROOT"
        case "$WINETRICKS_SUDO" in
        gksudo)
          # -l lazy unmount in case executable still running
          $WINETRICKS_SUDO "umount -l $W_ISO_MOUNT_ROOT"
          w_try $WINETRICKS_SUDO "rm -rf $W_ISO_MOUNT_ROOT"
          ;;
        *)
          $WINETRICKS_SUDO umount -l $W_ISO_MOUNT_ROOT
          w_try $WINETRICKS_SUDO rm -rf $W_ISO_MOUNT_ROOT
          ;;
        esac
        rm -f "$WINEPREFIX"/dosdevices/${W_ISO_MOUNT_LETTER}:
        rm -f "$WINEPREFIX"/dosdevices/${W_ISO_MOUNT_LETTER}::
    fi
}

w_ahk_do()
{
    if ! test -f "$W_CACHE/ahk/AutoHotkey.exe"
    then
        w_download ahk http://www.autohotkey.com/download/AutoHotkey104805.zip b3981b13fbc45823131f69d125992d6330212f27 
        w_try_unzip -d "$W_CACHE/ahk"  "$W_CACHE/ahk/AutoHotkey104805.zip" AutoHotkey.exe AU3_Spy.exe
        chmod +x "$W_CACHE/ahk/AutoHotkey.exe"
    fi

    _W_CR=`printf \\\\r`
    echo "$@" | sed "s/\$/$CR/" > "$W_TMP"/tmp.ahk
    $WINE "$W_CACHE_WIN/ahk/AutoHotkey.exe" "$W_TMP_WIN"\\tmp.ahk
    unset _W_CR
}

# Function to protect wine-specific sections of code.
# Outputs a message to console explaining what's being skipped.
# Usage:
#   if w_skip_windows name-of-operation
#   then
#      return
#   fi
#   ... do something that doesn't make sense on windows ...

w_skip_windows()
{
    case "$OS" in
    "Windows_NT")
      echo "Skipping operation '$1' on Windows"
      return 0
      ;;
    esac
    return 1
}

w_override_dlls()
{
    w_skip_windows w_override_dlls && return

    _W_mode=$1
    if [ $_W_mode = "disabled" ]
    then
        _W_mode=""
    fi
    shift
    echo Using $_W_mode override for following DLLs: $@
    cat > "$W_TMP"/override-dll.reg <<_EOF_
REGEDIT4

[HKEY_CURRENT_USER\Software\Wine\DllOverrides]
_EOF_
    while test "$1" != ""
    do
        case "$1" in
        comctl32)
           rm -rf "$W_WINDIR_UNIX"/winsxs/manifests/x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.2600.2982_none_deadbeef.manifest
           ;;
        esac

        # Note: if you want to override even DLLs loaded with an absolute path,
        # you need to add an asterisk:
        echo "\"*$1\"=\"$_W_mode\"" >> "$W_TMP"/override-dll.reg
        #echo "\"$1\"=\"$_W_mode\"" >> "$W_TMP"/override-dll.reg

        shift
    done

    w_try_regedit "$W_TMP_WIN"\\override-dll.reg

    unset _W_mode
}

w_override_no_dlls()
{
    w_skip_windows override && return

    $WINE regedit /d 'HKEY_CURRENT_USER\Software\Wine\DllOverrides'
}

w_override_all_dlls()
{
    # Disable all but the commonly used DLLs Wine doesn't have a credible alternative for
    # i.e. Don't disallow msvcp80 or d3dx9_* for now
    # d3dx9_24.dll d3dx9_25.dll d3dx9_26.dll d3dx9_27.dll d3dx9_28.dll d3dx9_29.dll d3dx9_30.dll d3dx9_31.dll d3dx9_32.dll d3dx9_33.dll d3dx9_34.dll d3dx9_35.dll d3dx9_36.dll d3dx9_37.dll d3dx9_38.dll d3dx9_39.dll d3dx9_40.dll d3dx9_41.dll d3dx9_42.dll d3dxof.dll 
    w_override_dlls builtin \
        acledit aclui activeds actxprxy advapi32 advpack amstream atl authz avicap32 \
        avifil32 avifilebavrt bcrypt browseui cabinet capi2032 cards cfgmgr32 clusapi \
        comcat comctl32 comdlg32 commdlg compobj compstui credui crtdll crypt32 cryptdlg \
        cryptdll cryptnet cryptui ctapi32 ctl3d ctl3d32 ctl3dv2 d3d10 \
        d3d10core d3d8 d3d9 d3dim d3drm \
        d3dxof dbghelp dciman32 ddeml ddraw ddrawex \
        devenum dinput dinput8 dispdib dispex dmband dmcompos dmime dmloader dmscript \
        dmstyle dmsynth dmusic dmusic32 dnsapi dplay dplayx dpnaddr dpnet dpnhpast \
        dpnlobby dpwsockx drmclien dsound dssenh dswave dwmapi dxdiagn dxgi faultrep \
        fltlib fusion fwpuclnt gdi32 gdiplus glu32 gpkcsp hal hid hlink \
        hnetcfg httpapi iccvid icmp imagehlp imm imm32 inetcomm inetmib1 infosoft \
        initpki inkobj inseng iphlpapi itircl itss jscript kernel32 loadperf localspl \
        localui lz32 lzexpand mapi32 mapistub mciavi32 mcicda mciqtz32 mciseq mciwave \
        midimap mlang mmdevapi mmsystem mpr mprapi msacm msacm32 mscat32 mscms \
        mscoree msctf msdaps msdmo msftedit mshtml msi msimg32 msimtf msisip \
        msnet32 msrle32 mssign32 mssip32 mstask msvcirt msvcr70 msvcr71 msvcr80 \
        msvcr90 msvcrt msvcrt20 msvcrt40 msvcrtd msvfw32 msvidc32 msvideo mswsock msxml3 \
        msxml4 nddeapi netapi32 newdev ntdll ntdsapi ntprint objsel odbc32 odbccp32 \
        ole2 ole2conv ole2disp ole2nls ole2prox ole2thk ole32 oleacc oleaut32 olecli \
        olecli32 oledb32 oledlg olepro32 olesvr olesvr32 olethk32 openal32 opengl32 pdh \
        pidgen powrprof printui propsys psapi pstorec qcap qedit qmgr qmgrprxy \
        quartz query rasapi16 rasapi32 rasdlg resutils riched20 riched32 rpcrt4 rsabase \
        rsaenh rtutils sccbase schannel secur32 security sensapi serialui setupapi setupx \
        sfc sfc_os shdoclc shdocvw shell shell32 shfolder shlwapi slbcsp slc \
        snmpapi softpub spoolss sti storage stress svrapi sxs t2embed tapi32 \
        toolhelp traffic twain twain_32 typelib unicows updspapi url urlmon user32 \
        userenv usp10 uxtheme vdmdbg ver version w32skrnl w32sys wbemprox wiaservc \
        win32s16 win87em winaspi windebug windowscodecs wined3d winedos winemapi wing wing32 \
        winhttp wininet winmm winnls winnls32 winscard winsock wintab wintab32 wintrust \
        wldap32 wmi wmiutils wnaspi32 wow32 ws2_32 wsock32 wtsapi32 wuapi wuaueng \
        xinput1_1 xinput1_2 xinput1_3 xinput9_1_0 xmllite
}

w_override_app_dlls()
{
    w_skip_windows w_override_app_dlls && return

    _W_app=$1
    shift
    _W_mode=$1
    shift
    echo Using $_W_mode override for following DLLs when running $_W_app: $@
    (
    echo REGEDIT4
    echo ""
    echo "[HKEY_CURRENT_USER\\Software\\Wine\\AppDefaults\\$app\\DllOverrides]"
    ) > "$W_TMP"/override-dll.reg

    while test "$1" != ""
    do
        case "$1" in
        comctl32)
           rm -rf "$W_WINDIR_UNIX"/winsxs/manifests/x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.2600.2982_none_deadbeef.manifest
           ;;
        esac
        echo "\"$1\"=\"$_W_mode\"" >> "$W_TMP"/override-dll.reg
        shift
    done

    w_try_regedit "$W_TMP_WIN"\\override-dll.reg
    rm "$W_TMP"/override-dll.reg
    unset _W_app _W_mode
}

# Has to be set in a few places...
w_set_winver()
{
    w_skip_windows w_set_winver && return
    # FIXME: This should really be done with winecfg, but it has no CLI options.

    # First, delete any lingering version info, otherwise it may conflict:
    (
    $WINE reg delete "HKLM\Software\Microsoft\Windows\CurrentVersion" /v SubVersionNumber /f || true
    $WINE reg delete "HKLM\Software\Microsoft\Windows\CurrentVersion" /v VersionNumber /f || true
    $WINE reg delete "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v CSDVersion /f || true
    $WINE reg delete "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v CurrentBuildNumber /f || true
    $WINE reg delete "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v CurrentVersion /f || true
    $WINE reg delete "HKLM\System\CurrentControlSet\Control\ProductOptions" /v ProductType /f || true
    $WINE reg delete "HKLM\System\CurrentControlSet\Control\ServiceCurrent" /v OS /f || true
    $WINE reg delete "HKLM\System\CurrentControlSet\Control\Windows" /v CSDVersion /f || true
    $WINE reg delete "HKCU\Software\Wine" /v Version /f || true
    ) > /dev/null 2>&1

    case $1 in
    win31)
        echo "Setting Windows version to $1"
        cat > "$W_TMP"/set-winver.reg <<_EOF_
REGEDIT4

[HKEY_USERS\S-1-5-4\Software\Wine]
"Version"="win31"

_EOF_

        w_try_regedit "$W_TMP_WIN"\\set-winver.reg
        return
        ;;
    win98)
        # This key is only used for win 95/98:

        echo "Setting Windows version to $1"
        cat > "$W_TMP"/set-winver.reg <<_EOF_
REGEDIT4

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion]
"SubVersionNumber"=" A "
"VersionNumber"="4.10.2222"

_EOF_
        w_try_regedit "$W_TMP_WIN"\\set-winver.reg
        return
        ;;
    nt40)
        # Similar to modern version, but sets two extra keys:

        echo "Setting Windows version to $1"
        cat > "$W_TMP"/set-winver.reg <<_EOF_
REGEDIT4

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion]
"CSDVersion"="Service Pack 6a"
"CurrentBuildNumber"="1381"
"CurrentVersion"="4.0"

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ProductOptions]
"ProductType"="WinNT"

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ServiceCurrent]
"OS"="Windows_NT"

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Windows]
"CSDVersion"=dword:00000600

_EOF_
        w_try_regedit "$W_TMP_WIN"\\set-winver.reg
        return
        ;;
    win2k)
        csdversion="Service Pack 4"
        currentbuildnumber="2195"
        currentversion="5.0"
        csdversion_hex=dword:00000400
        ;;
    winxp)
        csdversion="Service Pack 3"
        currentbuildnumber="2600"
        currentversion="5.1"
        csdversion_hex=dword:00000300
        ;;
    vista)
        csdversion="Service Pack 2"
        currentbuildnumber="6002"
        currentversion="6.0"
        csdversion_hex=dword:00000200
        ;;
    win7)
        csdversion="Service Pack 1"
        currentbuildnumber="7601"
        currentversion="6.1"
        csdversion_hex=dword:00000100
        ;;
    *)
        die "Invalid Windows version given."
        ;;
    esac

    echo "Setting Windows version to $1"
    cat > "$W_TMP"/set-winver.reg <<_EOF_
REGEDIT4

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion]
"CSDVersion"="$csdversion"
"CurrentBuildNumber"="$currentbuildnumber"
"CurrentVersion"="$currentversion"

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Windows]
"CSDVersion"=$csdversion_hex

_EOF_
    w_try_regedit "$W_TMP_WIN"\\set-winver.reg
}

w_unset_winver()
{
    w_set_winver winxp
}

# Present app $1 with the Windows personality $2
w_set_app_winver()
{
    w_skip_windows w_set_app_winver && return

    _W_app="$1"
    _W_version="$2"
    echo "Setting $_W_app to $_W_version mode"
    (
    echo REGEDIT4
    echo ""
    echo "[HKEY_CURRENT_USER\\Software\\Wine\\AppDefaults\\$_W_app]"
    echo "\"Version\"=\"$_W_version\""
    ) > "$W_TMP"/set-winver.reg

    w_try_regedit "$W_TMP_WIN"\\set-winver.reg
    rm "$W_TMP"/set-winver.reg
    unset _W_app
}

# Usage: workaround_wine_bug bugnumber [good-wineversion-shell-pattern]
# False (nonzero status) on Windows.
# True (zero status) on Wine unless good-wineversion-shell-pattern is set
# and matches the current wine version.
# For debugging: if you want to skip a bug's workaround, put the bug number in the
# environment variable WINETRICKS_BLACKLIST to disable it.
w_workaround_wine_bug()
{
    if test "$WINE" = ""
    then
        echo No need to work around wine bug $1 on windows
        return 1
    fi
    # FIXME: accept wine version number as $2, only apply if before that
    case $1 in
    "$WINETRICKS_BLACKLIST")
        echo wine bug $1 workaround blacklisted, skipping
        return 1
        ;;
    esac
    case $LANG in
    da*) w_warn "Arbejder uden om wine-fejl $1" ;;
    de*) w_warn "Wine-Fehler $1 wird umgegangen" ;;
    *)   w_warn "Working around wine bug $1" ;;
    esac
    return 0
}

# Function for verbs to register themselves so they show up in the menu.
# Example:
# w_metadata  wog games \
#   title="World of Goo Demo" \
#   pub="2D Boy" \
#   year="2008" \
#   media="download" \
#   file1="WorldOfGooDemo.1.0.exe"

w_metadata()
{
    if test "$installed_exe1" || test "$installed_file1" || test "$publisher" || test "$year"
    then
        w_die "bug: stray metadata tags set: somebody forgot a backslash in a w_metadata somewhere.  Run with sh -x to see where."
    fi
    if winetricks_metadata_exists $1
    then
        w_die "bug: a verb named $1 already exists."
    fi

    _W_md_cmd="$1"
    file="$WINETRICKS_METADATA/$2/$1.vars"
    shift
    shift
    # Echo arguments to file, with double quotes around the values.
    # Used to use perl here, but that was too slow on cygwin.
    for arg
    do
        # Use longest match when stripping value,
        # and shortest match when stripping name,
        # so descriptions can have embedded equals signs
        # FIXME: backslashes get interpreted here.  This screws up
        # installed_file1 fairly often.  Fortunately, we can use forward
        # slashes in that variable instead of backslashes.
        echo ${arg%%=*}=\"${arg#*=}\"
    done > "$file"
    # If the problem described above happens, you'd see errors like this:
    # /tmp/w.dank.4650/metadata/dlls/comctl32.vars: 6: Syntax error: Unterminated quoted string
    # so check for lines that aren't properly quoted.

    # Do sanity check unless running on cygwin, where it's way too slow.
    case "$OS" in
    "Windows_NT")
        ;;
    *)
        if grep '[^"]$' "$file"
        then
            w_die "bug: w_metadata $_W_md_cmd corrupt, might need forward slashes?"
        fi
        ;;
    esac
    unset _W_md_cmd
}

# Function for verbs to register their main executable.
# Example:
#   w_declare_exe "$W_PROGRAMS_X86_WIN\\WorldOfGooDemo" WorldOfGoo.exe
w_declare_exe()
{
    _W_dir="$1"
    _W_exe="$2"
    cat > "$W_DRIVE_C/run-$W_PACKAGE.bat" <<__EOF__
${W_PROGRAMS_DRIVE}:
cd "$_W_dir"
$_W_exe
__EOF__
    unset _W_dir _W_exe
}

# Call a verb, don't let it affect environment
# Hope that subshell passes through exit status
# Usage: w_do_call foo [bar]       (calls load_foo bar)
# Or: w_do_call foo=bar            (also calls load_foo bar)
# Or: w_do_call foo                (calls load_foo)
w_do_call()
{
    (
        case $1 in
        *=*) arg=`echo $1 | sed 's/.*=//'`; cmd=`echo $1 | sed 's/=.*//'`;;
        *) cmd=$1; arg=$2 ;;
        esac

        W_TMP="$W_DRIVE_C/windows/_temp/_$1"
        W_TMP_WIN="C:\\windows\\_temp\\_$1"
        rm -rf "$W_TMP"
        mkdir -p "$W_TMP"

        # Unset all known used metadata values, in case this is a nested call
        unset installed_dll1 installed_exe1

        if winetricks_metadata_exists $1
        then
            . "$WINETRICKS_METADATA"/*/$1.vars
        elif winetricks_metadata_exists $cmd
        then
            . "$WINETRICKS_METADATA"/*/$cmd.vars
        else
            w_die "No such verb $1"
        fi

        # Don't install if already installed
        if winetricks_is_installed $1
        then
            echo "$1 already installed, skipping"
            return 0
        fi

        # We'd like to get rid of W_PACKAGE, but for now, just set it as late as possible.
        W_PACKAGE=$1
        load_$cmd $arg

        # User-specific postinstall hook.
        # Source it so the script can call w_download() if needed.
        postfile="$WINETRICKS_POST/$1/$1-postinstall.sh"
        if test -f "$postfile"
        then
            chmod +x "$postfile"
            . "$postfile"
        fi

        # Clean up after this verb
        rm -rf "$W_TMP"
    )
    # Kludge: some verbs are allowed to affect the environment
    case $1 in
    sandbox)
        W_CACHE_WIN="`w_pathconv -w $W_CACHE | tr '\012' ' ' | sed 's/ $//'`"
        ;;
    esac
}

# If you want to check exit status yourself, use w_do_call
w_call()
{
    w_try w_do_call $@
}

w_register_font()
{
    file=$1
    shift
    font=$1

    case "$file" in
    *.TTF|*.ttf) font="$font (TrueType)";;
    esac

    # Kludge: use _r to avoid \r expansion in w_try
    cat > "$W_TMP"/_register-font.reg <<_EOF_
REGEDIT4

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts]
"$font"="$file"
_EOF_
    # too verbose
    w_try_regedit "$W_TMP_WIN"\\_register-font.reg
    cp "$W_TMP"/*.reg /tmp/_reg$$.reg

    # Wine also updates the win9x fonts key, so let's do that, too
    cat > "$W_TMP"/_register-font.reg <<_EOF_
REGEDIT4

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Fonts]
"$font"="$file"
_EOF_
    w_try_regedit "$W_TMP_WIN"\\_register-font.reg
    cp "$W_TMP"/*.reg /tmp/_reg$$-2.reg
}

w_register_font_substitution()
{
    _W_alias=$1
    shift
    _W_font=$1
    # Kludge: use _r to avoid \r expansion in w_try
    cat > "$W_TMP"/_register-font-sub.reg <<_EOF_
REGEDIT4

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes]
"$_W_alias"="$_W_font"
_EOF_
    w_try_regedit "$W_TMP_WIN"\\_register-font-sub.reg
    unset _W_alias _W_font
}

w_append_path()
{
    # Prepend $1 to the windows path in the registry.
    _W_NEW_PATH="`echo $1| sed 's,\\\\,\\\\\\\\,g'`"
    _W_WIN_PATH="`WINEDEBUG= $WINE cmd.exe /c echo "%PATH%" | tr -d '\r' | sed 's,\\\\,\\\\\\\\,g'`"

    sed 's/$/\r/' > "$W_TMP"/path.reg <<_EOF_
REGEDIT4

[HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Environment]
"PATH"="$_W_NEW_PATH;$_W_WIN_PATH"
_EOF_

    w_try_regedit "$W_TMP_WIN"\\path.reg
    rm -f "$W_TMP"/path.reg
    unset _W_NEW_PATH _W_WIN_PATH
}
 
#---- Private Functions ----

winetricks_print_version() {
    echo "$WINETRICKS_VERSION"
}

# Run a windows command without triggering wine's mshtml's gecko install dialog
winetricks_early_wine()
{
    WINEDEBUG=-all WINEDLLOVERRIDES=mshtml= $WINE "$@"
}

winetricks_detect_gui()
{
    if test -x "`which zenity 2>/dev/null`"
    then
        WINETRICKS_GUI=zenity

        WINETRICKS_MENU_HEIGHT=500
        WINETRICKS_MENU_WIDTH=900

        # Reduce menu size if bigger than screen
        XRANDR="`which xrandr`"
        if test -x "$XRANDR"
        then
            XRANDR_WIDTH=`$XRANDR -q | awk '/current/ {print $8}'`
            XRANDR_HEIGHT=`$XRANDR -q | awk '/current/ {print $10}' | sed 's/,//'`
            if test "$XRANDR_HEIGHT" -gt 400 -a "$XRANDR_HEIGHT" -lt $WINETRICKS_MENU_HEIGHT
            then
                WINETRICKS_MENU_HEIGHT=$XRANDR_HEIGHT
            fi
            if test "$XRANDR_WIDTH" -gt 400 -a "$XRANDR_WIDTH" -lt $WINETRICKS_MENU_WIDTH
            then
                WINETRICKS_MENU_WIDTH=$XRANDR_WIDTH
            fi
        fi
    elif test -x "`which kdialog 2>/dev/null`"
    then
        echo "Zenity not found!  Using kdialog as poor substitute."
        WINETRICKS_GUI=kdialog
    else
        echo "Please install zenity if you want a graphical interface."
        exit 1
    fi
}

# Detect which sudo to use
winetricks_detect_sudo()
{
    WINETRICKS_SUDO=sudo
    if test "$WINETRICKS_GUI" = "none"
    then
        return
    fi
    if test x"$DISPLAY" != x""
    then
        if test -x "`which gksudo 2>/dev/null`"
        then
            WINETRICKS_SUDO=gksudo
        elif test -x "`which kdesudo 2>/dev/null`"
        then
            WINETRICKS_SUDO=kdesudo
        fi
    fi
}

# Display main menu, get which submenu the user wants
winetricks_mainmenu()
{
    case $LANG in
    da*) _W_msg_title='Vælg en pakke-kategori'
         _W_msg_body='Hvad ønsker du at gøre?'
         _W_msg_apps='Installér et program'
         _W_msg_benchmarks='Install a Windows benchmark'
         _W_msg_dlls="Install a Windows DLL"
         _W_msg_fonts='Install a font'
         _W_msg_games='Installér et spil'
         _W_msg_settings='Change Wine settings'
         _W_msg_unattended0="Switch to attended mode, i.e. non-automatic installs"
         _W_msg_unattended1="Switch to unattended mode, i.e. automatic installs"
         ;;
    de*) _W_msg_title='Pakettyp auswählen'
         _W_msg_body='Was möchten Sie tun?'
         _W_msg_apps='Windows-Programm installieren'
         _W_msg_benchmarks='Windows-Benchmark installieren'
         _W_msg_dlls="Windows-DLL installieren"
         _W_msg_fonts='Schriftart installieren'
         _W_msg_games='Windows-Spiel installieren'
         _W_msg_settings='Change Wine settings'
         _W_msg_unattended0="Switch to attended mode, i.e. non-automatic installs"
         _W_msg_unattended1="Switch to unattended mode, i.e. automatic installs"
         ;;
    *)   _W_msg_title="Winetricks - current bottle is '$WINEPREFIX'"
         _W_msg_body='What would you like to do with Wine?'
         _W_msg_apps='Install other software'
         _W_msg_benchmarks='Install a benchmark'
         _W_msg_dlls="Install a DLL"
         _W_msg_fonts='Install a font'
         _W_msg_games='Install a game'
         _W_msg_settings='Change settings'
         _W_msg_unattended0="Switch to attended mode, i.e. non-automatic installs"
         _W_msg_unattended1="Switch to unattended mode, i.e. automatic installs"
         ;;
    esac
    case "$W_OPT_UNATTENDED" in
    1) _W_cmd_unattended=attended; _W_msg_unattended="$_W_msg_unattended0" ;;
    *) _W_cmd_unattended=unattended; _W_msg_unattended="$_W_msg_unattended1" ;;
    esac

    # FIXME: don't show uninstall option when $WINETRICKS_OPT_SHAREDPREFIX is 1

    case $WINETRICKS_GUI in
    zenity)
        zenity \
            --title "$_W_msg_title" \
            --text "$_W_msg_body" \
            --list \
            --radiolist \
            --column '' \
            --column '' \
            --column '' \
            --height $WINETRICKS_MENU_HEIGHT \
            --width $WINETRICKS_MENU_WIDTH \
            --hide-column 2 \
            FALSE dlls       "$_W_msg_dlls" \
            FALSE fonts      "$_W_msg_fonts" \
            FALSE games      "$_W_msg_games" \
            FALSE benchmarks "$_W_msg_benchmarks" \
            FALSE apps       "$_W_msg_apps" \
            FALSE settings   "$_W_msg_settings" \
            FALSE $_W_cmd_unattended "$_W_msg_unattended" \
         | tr '|' ' '
        ;;

    kdialog)
        kdialog --geometry 600x400+100+100 \
                --title "$_W_msg_title" \
                --separate-output \
                --radiolist \
                "$_W_msg_body"\
                dlls       "$_W_msg_dlls" off \
                fonts      "$_W_msg_fonts" off \
                games      "$_W_msg_games" off \
                benchmarks "$_W_msg_benchmarks" off \
                apps       "$_W_msg_apps" off \
                settings   "$_W_msg_settings" off \
                $_W_cmd_unattended "$_W_msg_unattended" off \

        ;;
    esac
    unset _W_msg_body _W_msg_title _W_msg_apps _W_msg_benchmarks _W_msg_dlls _W_msg_games _W_msg_settings
}

# Display the menu of installed apps, output list of selected apps
winetricks_installed_menu()
{
    case $WINETRICKS_CURMENU in
    run)
        case $LANG in
        de*) _W_msg_title='Pakete auswählen'
             _W_msg_body='Welches Programm möchten Sie starten?'
             ;;
        *)   _W_msg_title='Select a program to run'
             _W_msg_body='Which program would you like to run?'
             ;;
        esac
        ;;
    uninstall)
        case $LANG in
        de*) _W_msg_title='Pakete auswählen'
             _W_msg_body='Welches Programm möchten Sie löschen?'
             ;;
        *)   _W_msg_title='Select a program to delete'
             _W_msg_body='Which program would you like to uninstall?'
             ;;
        esac
        ;;
    esac

    case $WINETRICKS_GUI in
    zenity)
        case $LANG in
        da*) echo -n "zenity \
                --title '$_W_msg_title' \
                --text '$_W_msg_body' \
                --list \
                --checklist \
                --column '' \
                --column Pakke \
                --column Navn \
                --column Udgiver \
                --column År \
                --column Medie \
                --height $WINETRICKS_MENU_HEIGHT \
                --width $WINETRICKS_MENU_WIDTH \
                "
             ;;
       de*) echo -n "zenity \
                --title '$_W_msg_title' \
                --text '$_W_msg_body' \
                --list \
                --checklist \
                --column '' \
                --column Paket \
                --column Name \
                --column Herausgeber \
                --column Jahr \
                --column Media \
                --height $WINETRICKS_MENU_HEIGHT \
                --width $WINETRICKS_MENU_WIDTH \
                "
             ;;
        *) echo -n "zenity \
                --title '$_W_msg_title' \
                --text '$_W_msg_body' \
                --list \
                --checklist \
                --column '' \
                --column Package \
                --column Title \
                --column Publisher \
                --column Year \
                --column Media \
                --height $WINETRICKS_MENU_HEIGHT \
                --width $WINETRICKS_MENU_WIDTH \
                "
             ;;
        esac > "$WINETRICKS_WORKDIR"/zenity.sh

        for verb in `winetricks_list_installed`
        do
            metadatafile="`echo "$WINETRICKS_METADATA"/*/$verb.vars`"
            if ! test -f "$metadatafile"
            then
                continue
            fi
            (
            title='?'
            author='?'
            . $metadatafile
            echo -n " " FALSE \
                    $verb \
                    "\"$title\"" \
                    "\"$publisher\"" \
                    "\"$year\"" \
                    "\"$media\""
            )
        done >> $WINETRICKS_WORKDIR/zenity.sh

        sh "$WINETRICKS_WORKDIR"/zenity.sh | tr '|' ' '
        ;;

    kdialog)
        (
        echo -n "kdialog --geometry 600x400+100+100 --title '$_W_msg_title' --separate-output --checklist '$_W_msg_body' "
        winetricks_list_installed | sed 's/\(.*\)/\1 \1 off/' | tr '\012' ' '
        ) > "$WINETRICKS_WORKDIR"/kdialog.sh
        sh "$WINETRICKS_WORKDIR"/kdialog.sh
        ;;
    esac

    unset _W_msg_body _W_msg_title _W_msg_apps _W_msg_games
}

winetricks_settings_menu()
{
    case $LANG in
    *)   _W_msg_title='Pick a setting'
         _W_msg_body='Which setting(s) would you like to change?'
         ;;
    esac

    case $WINETRICKS_GUI in
    zenity)
        case $LANG in
        da*) echo -n "zenity \
                --title '$_W_msg_title' \
                --text '$_W_msg_body' \
                --list \
                --checklist \
                --column '' \
                --column Pakke \
                --column Navn \
                --height $WINETRICKS_MENU_HEIGHT \
                --width $WINETRICKS_MENU_WIDTH \
                "
             ;;
       de*) echo -n "zenity \
                --title '$_W_msg_title' \
                --text '$_W_msg_body' \
                --list \
                --checklist \
                --column '' \
                --column Paket \
                --column Name \
                --height $WINETRICKS_MENU_HEIGHT \
                --width $WINETRICKS_MENU_WIDTH \
                "
             ;;
        *) echo -n "zenity \
                --title '$_W_msg_title' \
                --text '$_W_msg_body' \
                --list \
                --checklist \
                --column '' \
                --column Setting \
                --column Title \
                --height $WINETRICKS_MENU_HEIGHT \
                --width $WINETRICKS_MENU_WIDTH \
                "
             ;;
        esac > "$WINETRICKS_WORKDIR"/zenity.sh

        for metadatafile in "$WINETRICKS_METADATA"/$WINETRICKS_CURMENU/*.vars
        do
            code=`winetricks_metadata_basename $metadatafile`
            (
            title='?'
            author='?'
            . $metadatafile
            echo -n " " FALSE \
                    $code \
                    "\"$title\""
            )
        done >> $WINETRICKS_WORKDIR/zenity.sh

        sh "$WINETRICKS_WORKDIR"/zenity.sh | tr '|' ' '
        ;;

    kdialog)
        (
        echo -n "kdialog --geometry 600x400+100+100 --title '$_W_msg_title' --separate-output --checklist '$_W_msg_body' "
        winetricks_list_all | sed 's/\([^ ]*\)  *\(.*\)/\1 "\1 - \2" off /' | tr '\012' ' '
        ) > "$WINETRICKS_WORKDIR"/kdialog.sh
        sh "$WINETRICKS_WORKDIR"/kdialog.sh
        ;;
    esac

    unset _W_msg_body _W_msg_title
}

# Display the current menu, output list of verbs to execute to stdout
winetricks_showmenu()
{
    case $LANG in
    da*) _W_msg_title='Vælg en pakke'
         _W_msg_body='Vilken pakke vil du installere?'
         ;;
    de*) _W_msg_title='Pakete auswählen'
         _W_msg_body='Welche Pakete möchten Sie installieren?'
         ;;
    *)   _W_msg_title='Select a package to install'
         _W_msg_body='Which package(s) would you like to install?'
         ;;
    esac

    case $WINETRICKS_GUI in
    zenity)
        case $LANG in
        da*) echo -n "zenity \
                --title '$_W_msg_title' \
                --text '$_W_msg_body' \
                --list \
                --checklist \
                --column '' \
                --column Pakke \
                --column Navn \
                --column Udgiver \
                --column År \
                --column Medie \
                --height $WINETRICKS_MENU_HEIGHT \
                --width $WINETRICKS_MENU_WIDTH \
                "
             ;;
       de*) echo -n "zenity \
                --title '$_W_msg_title' \
                --text '$_W_msg_body' \
                --list \
                --checklist \
                --column '' \
                --column Paket \
                --column Name \
                --column Herausgeber \
                --column Jahr \
                --column Media \
                --height $WINETRICKS_MENU_HEIGHT \
                --width $WINETRICKS_MENU_WIDTH \
                "
             ;;
        *) echo -n "zenity \
                --title '$_W_msg_title' \
                --text '$_W_msg_body' \
                --list \
                --checklist \
                --column '' \
                --column Package \
                --column Title \
                --column Publisher \
                --column Year \
                --column Media \
                --height $WINETRICKS_MENU_HEIGHT \
                --width $WINETRICKS_MENU_WIDTH \
                "
             ;;
        esac > "$WINETRICKS_WORKDIR"/zenity.sh

        for metadatafile in "$WINETRICKS_METADATA"/$WINETRICKS_CURMENU/*.vars
        do
            code=`winetricks_metadata_basename $metadatafile`
            (
            title='?'
            author='?'
            . $metadatafile
            echo -n " " FALSE \
                    $code \
                    "\"$title\"" \
                    "\"$publisher\"" \
                    "\"$year\"" \
                    "\"$media\""
            )
        done >> $WINETRICKS_WORKDIR/zenity.sh

        sh "$WINETRICKS_WORKDIR"/zenity.sh | tr '|' ' '
        ;;

    kdialog)
        (
        echo -n "kdialog --geometry 600x400+100+100 --title '$_W_msg_title' --separate-output --checklist '$_W_msg_body' "
        winetricks_list_all | sed 's/\([^ ]*\)  *\(.*\)/\1 "\1 - \2" off /' | tr '\012' ' '
        ) > "$WINETRICKS_WORKDIR"/kdialog.sh
        sh "$WINETRICKS_WORKDIR"/kdialog.sh
        ;;
    esac

    unset _W_msg_body _W_msg_title
}

# Converts a metadata abolute path to its app code
winetricks_metadata_basename()
{
    # Classic, but too slow on cygwin
    #basename $1 .vars

    # first, remove suffix .vars
    _W_mb_tmp=${1%.vars}
    # second, remove any directory prefix
    echo ${_W_mb_tmp##*/}
    unset _W_mb_tmp
}

# Returns true if given verb has been registered
winetricks_metadata_exists()
{
   test -f "$WINETRICKS_METADATA"/*/$1.vars
}

# Returns true if given verb has been cached
# You must have already loaded its metadata before calling
winetricks_is_cached()
{
    # FIXME: also check file2... if given
    _W_path="$W_CACHE/$1/$file1"
    case "$_W_path" in
    *..*)
        # Remove /foo/.. so verbs that don't have their own cache directories
        # can refer to siblings
        _W_path="`echo $_W_path | sed 's,/[^/]*/\.\.,,'`"
        ;;
    esac
    if test -f "$_W_path"
    then
        unset _W_path
        return 0
    fi
    unset _W_path
    return 1
}

# Returns true if given verb has been installed
# You must have already loaded its metadata before calling
winetricks_is_installed()
{
    unset _W_file
    if test "$installed_exe1"
    then
        _W_file="$installed_exe1"
    elif test "$installed_file1"
    then
        _W_file="$installed_file1"
    fi
    if test "$_W_file"
    then
        _W_file_unix="`w_pathconv -u "$_W_file"`"
        if test -f "$_W_file_unix" && ! grep -q "Wine placeholder DLL" "$_W_file_unix"
        then
            unset _W_file _W_file_unix
            return 0  # installed
        fi
    fi
    unset _W_file _W_file_unix
    return 1  # not installed
}

# List verbs which are already fully cached locally
winetricks_list_cached()
{
    for _W_metadatafile in "$WINETRICKS_METADATA"/*/*.vars
    do
        # Use a subshell to avoid putting metadata in global space
        # If this is too slow, we can unset known metadata by hand
        (
        code=`winetricks_metadata_basename $_W_metadatafile`
        . $_W_metadatafile
        if winetricks_is_cached $code
        then
            echo $code
        fi
        )
    done | sort
    unset _W_metadatafile
}

# List verbs which are automatically downloadable, regardless of whether they're cached yet
winetricks_list_download()
{
    cd "$WINETRICKS_METADATA"
    grep -l 'media=.download' */*.vars | sed 's,.*/,,;s/\.vars//' | sort -u
}

# List verbs which are downloadable with user intervention, regardless of whether they're cached yet
winetricks_list_manual_download()
{
    cd "$WINETRICKS_METADATA"
    grep -l 'media=.manual_download' */*.vars | sed 's,.*/,,;s/\.vars//' | sort -u
}

winetricks_list_installed()
{
    (
    case $WINETRICKS_OPT_SHAREDPREFIX in
    0)
        # assume there's only one app per bottle (!), and list the bottles that have a matching run batch file.
        for verb in `ls "$W_PREFIXES_ROOT"/*/dosdevices/c:/run-*.bat | sed 's,.*/\([^/]*\)/dosdevices.*,\1,' `
        do
            test -f "$W_PREFIXES_ROOT"/$verb/dosdevices/c:/run-$verb.bat && echo $verb
        done
        ;;
    1)
        # List packages in default bottle
        for _W_metadatafile in "$WINETRICKS_METADATA"/*/*.vars
        do
            # Use a subshell to avoid putting metadata in global space
            # If this is too slow, we can unset known metadata by hand
            (
            code=`winetricks_metadata_basename $_W_metadatafile`
            . $_W_metadatafile
            if winetricks_is_installed $code
            then
                echo $code
            fi
            )
        done | sort
        unset _W_metadatafile
        ;;
    esac

    ) | sort -u
}

# Helper for adding a string to a list of flags
winetricks_append_to_flags()
{
    if test "$flags"
    then
        flags="$flags,"
    fi
    flags="${flags}$1"
}

# List all verbs in category WINETRICKS_CURMENU verbosely
# Format is "verb  title  (publisher, year) [flags]"
winetricks_list_all()
{
    case $WINETRICKS_CURMENU in
    main) echo "$WINETRICKS_CATEGORIES" | tr ' ' '\012' ; return;;
    esac

    case $LANG in
    da*) _W_cached="cached"   ; _W_download="kan hentes"    ;;
    de*) _W_cached="gecached" ; _W_download="herunterladbar";;
    *)   _W_cached="cached"   ; _W_download="downloadable"  ;;
    esac

    for _W_metadatafile in "$WINETRICKS_METADATA"/$WINETRICKS_CURMENU/*.vars
    do
        # Use a subshell to avoid putting metadata in global space
        # If this is too slow, we can unset known metadata by hand
        (
        code=`winetricks_metadata_basename $_W_metadatafile`
        . $_W_metadatafile

        # Compute cached and downloadable flags
        flags=""
        test "$media" = "download" && winetricks_append_to_flags "$_W_download"
        winetricks_is_cached $code   && winetricks_append_to_flags "$_W_cached"
        test "$flags" && flags="[$flags]"

        if ! test "$year" && ! test "$publisher"
        then
            printf "%-24s %s %s\n" $code "$title" "$flags"
        else
            printf "%-24s %s (%s, %s) %s\n" $code "$title" "$publisher" "$year" "$flags"
        fi
        )
    done
    unset _W_cached _W_metadatafile
}

# Abort if user doesn't own the given directory (or its parent, if it doesn't exist yet)
winetricks_die_if_user_not_dirowner()
{
    if test -d "$1"
    then
        _W_checkdir="$1"
    else
        # fixme: quoting problem?
        _W_checkdir=`dirname "$1"`
    fi
    _W_nuser=`id -u`
    _W_nowner=`ls -l -n -d -L "$_W_checkdir" | awk '{print $3}'`
    if test x$_W_nuser != x$_W_nowner
    then
        w_die "You (`id -un`) don't own $_W_checkdir.  Don't run this tool as another user!"
    fi
}

# See
# http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf (iso9660)
# http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-167.pdf
# http://www.osta.org/specs/pdf/udf102.pdf
# http://www.ecma-international.org/publications/techreports/E-TR-071.htm

# Usage: read_bytes offset count device
winetricks_read_bytes()
{
    dd status=noxfer if=$3 bs=1 skip=$1 count=$2 2>/dev/null
}

# Usage: read_hex offset count device
winetricks_read_hex()
{
    hexdump -s $1 -n $2 -e $2'/1 "%01x " "\n"' $3 | sed 's/  *$//'
}

# Usage: read_decimal offset device
# Reads four byte word, outputs in decimal.
# Uses default endianness.
# udf uses little endian words, so this only works on little endian machines.
winetricks_read_decimal()
{
    hexdump -s $1 -n 4 -e '1/4 "%4d " "\n"' $2
}

winetricks_read_udf_volume_name()
{
    # "Anchor volume descriptor pointer" starts at sector 256

    # AVDP Layout (ECMA-167 3/10.2):
    # size   offset   contents
    # 16     0        descriptor tag (id = 2)
    # 16     8        main (primary?) volume descriptor sequence extent
    # ...

    # descriptor tag layout (ECMA-167 3/7.2):
    # size   offset   contents
    # 2      0        TagIdentifier
    # ...

    # extent layout (ECMA-167 3/7.1):
    # size   offset   contents
    # 4      0        length (in bytes)
    # 8      4        location (in 2k sectors)

    # primary volume descriptor layout (ECMA-167 3/10.1):
    # size   offset   contents
    # 16     0        descriptor tag (id = 1)
    # ...
    # 32     24       volume identifier (dstring)

    # 1. check the 16 bit TagIdentifier of the descriptor tag, make sure it's 2
    tagid=`winetricks_read_hex 524288 2 $1`
    : echo tagid is $tagid
    case "$tagid" in
    "2 0") : echo Found AVDP ;;
    *) echo "Did not find AVDP (tagid was $tagid)"; exit 1;;
    esac

    # 2. read the location of the main volume descriptor:
    offset=`winetricks_read_decimal 524308 $1`
    : echo MVD is at sector $offset
    offset=`expr $offset \* 2048`
    : echo MVD is at byte $offset

    # 3. check the TagIdentifier of the MVD's descriptor tag, make sure it's 1
    tagid=`winetricks_read_hex $offset 2 $1`
    : echo tagid is $tagid
    case "$tagid" in
    "1 0") : echo Found MVD ;;
    *) echo Did not find MVD; exit 1;;
    esac

    # 4. Read whether the name is in 8 or 16 bit chars
    offset=`expr $offset + 24`
    width=`winetricks_read_hex $offset 1 $1`

    offset=`expr $offset + 1`

    # 5. Profit!
    case $width in
    8)   winetricks_read_bytes $offset 30 $1 | sed 's/  *$//' ;;
    10)  winetricks_read_bytes $offset 30 $1 | tr -d '\000' | sed 's/  *$//' ;;
    *) echo "Unhandled dvd volname character width '$width'"; exit 1;;
    esac

    echo ""
}

winetricks_read_iso9660_volume_name()
{
    winetricks_read_bytes 32808 30 $1 | sed 's/  *$//'
}

winetricks_read_volume_name()
{
    # ECMA-119 says that CD-ROMs have sector size 2k, and at sector 16 have:
    # size  offset contents
    #  1    0      Volume descriptor type (1 for primary volume descriptor)
    #  5    1      Standard identifier ("CD001" for iso9660)
    # ECMA-167, section 9.1.2, has a table of standard identifiers:
    # "BEA01": ecma-167 9.2, Beginning Extended Area Descriptor
    # "CD001": ecma-119
    # "CDW02": ecma-168

    std_id=`winetricks_read_bytes 32769 5 $1`
    : echo std_id is $std_id

    case $std_id in
    CD001) winetricks_read_iso9660_volume_name $1 ;;
    BEA01) winetricks_read_udf_volume_name $1; ;;
    *) echo "Unrecognized disk type $std_id"; exit 1 ;;
    esac
}

winetricks_volname()
{
    x=`volname $1 2> /dev/null| sed 's/  *$//'`
    if test "x$x" = "x"
    then
        # UDF?  See https://bugs.launchpad.net/bugs/678419
        x=`winetricks_read_volume_name $1`
    fi
    echo $x
}

# Really, should take a volume name as argument, and use 'mount' to get
# mount point if system automounted it.
winetricks_detect_optical_drive()
{
    case "$WINETRICKS_DEV" in
    "") ;;
    *) return ;;
    esac

    for WINETRICKS_DEV in /dev/cdrom /dev/dvd /dev/sr0
    do
        test -b $WINETRICKS_DEV && break
    done

    case "$WINETRICKS_DEV" in
    "x") w_die "can't find cd/dvd drive" ;;
    esac
}

winetricks_cache_iso()
{
    # WINETRICKS_IMG has already been set by w_mount
    _W_expected_volname="$1"

    winetricks_die_if_user_not_dirowner "$W_CACHE"
    winetricks_detect_optical_drive

    # Horrible hack for Gentoo - make sure we can read from the drive
    if ! test -r $WINETRICKS_DEV
    then
        case "$WINETRICKS_SUDO" in
        gksudo) $WINETRICKS_SUDO "chmod 666 $WINETRICKS_DEV" ;;
        *) $WINETRICKS_SUDO chmod 666 $WINETRICKS_DEV ;;
        esac
    fi

    while true
    do
        # Wait for user to insert disc.
        # Sleep long to make it less likely to close the drive during insertion.
        while ! dd if=$WINETRICKS_DEV of=/dev/null count=1
        do
            sleep 5
        done

        # Some distros automount discs in /media, take advantage of that
        if test -d "/media/_W_expected_volname"
        then
            break
        fi
        # Otherwise try and read it straight from unmounted volume
        _W_volname=`winetricks_volname $WINETRICKS_DEV`
        if test "$_W_expected_volname" != "$_W_volname"
        then
            case $LANG in
            da*)  w_warn "Forkert disk [$_W_volname] indsat. Indsæt venligst disken [$_W_expected_volname]" ;;
            de*)  w_warn "Falsche Disk [$_W_volname] eingelegt.  Bitte legen Sie Disk [$_W_expected_volname] ein!" ;;
            *)    w_warn "Wrong disc [$_W_volname] inserted.  Please insert disc [$_W_expected_volname]" ;;
            esac

            sleep 10
        else
            break
        fi
    done

    # Copy disc to .iso file, display progress every 5 seconds
    # Use conv=noerror,sync to replace unreadable blocks with zeroes
    case $WINETRICKS_OPT_DD in
    dd)
      dd if=$WINETRICKS_DEV of="$W_CACHE"/temp.iso bs=2048 conv=noerror,sync &
      WINETRICKS_DD_PID=$!
      ;;
    ddrescue)
      if test "`which ddrescue`" = ""
      then
          w_die "Please install ddrescue first."
      fi
      ddrescue -v -b 2048 $WINETRICKS_DEV "$W_CACHE"/temp.iso &
      WINETRICKS_DD_PID=$!
      ;;
    esac

    # Note: if user presses ^C, winetricks_cleanup will call winetricks_iso_cleanup
    while ps -p $WINETRICKS_DD_PID > /dev/null 2>&1
    do
      sleep 5
      ls -l "$W_CACHE"/temp.iso
    done
    unset WINETRICKS_DD_PID

    mv "$W_CACHE"/temp.iso "$WINETRICKS_IMG"

    eject $WINETRICKS_DEV || true    # punt if eject not found (as on cygwin)
}

winetricks_mount_cached_iso()
{
    # On entry, WINETRICKS_IMG is already set
    w_umount

    if test "$WINE" = ""
    then
        w_die Windows not yet supported
    else
        # Linux
        # FIXME: find a way to mount or copy from image without sudo
        _W_USERID=`id -u`
        case "$WINETRICKS_SUDO" in
        gksudo)
          w_try $WINETRICKS_SUDO "mkdir -p $W_ISO_MOUNT_ROOT"
          w_try $WINETRICKS_SUDO "mount -o ro,loop,uid=$_W_USERID,unhide $WINETRICKS_IMG $W_ISO_MOUNT_ROOT"
          ;;
        *)
          w_try $WINETRICKS_SUDO mkdir -p $W_ISO_MOUNT_ROOT
          w_try $WINETRICKS_SUDO mount -o ro,loop,uid=$_W_USERID,unhide "$WINETRICKS_IMG" $W_ISO_MOUNT_ROOT
          ;;
        esac

        echo "Mounting as drive ${W_ISO_MOUNT_LETTER}:"
        # Gotta provide a symlink to the raw disc, else installers that check volume names will fail
        rm -f "$WINEPREFIX/dosdevices/${W_ISO_MOUNT_LETTER}:"*
        ln -sf "$WINETRICKS_IMG" "$WINEPREFIX/dosdevices/${W_ISO_MOUNT_LETTER}::"
        ln -sf "$W_ISO_MOUNT_ROOT" "$WINEPREFIX/dosdevices/${W_ISO_MOUNT_LETTER}:"
        unset _W_USERID
    fi
}

# List the currently mounted udf or iso9660 filesystems that match the given pattern
# Output format:
#   dev mountpoint
#   dev mountpoint
#   ...
# Mountpoints may contain spaces.

winetricks_list_mounts()
{
    mount | egrep 'udf|iso9660' | sed 's,^\([^ ]*\) on \(.*\) type .*,\1 \2,'| grep "$1\$"
}

# Return success and set _W_dev _W_mountpoint if volume $1 is mounted
# Note: setting variables as a way of returning results from a
# shell function exposed several bugs in most shells (except ksh!)
# related to implicit subshells.  It would be better to output
# one string to stdout instead.
winetricks_is_mounted()
{
    # First, check for matching mountpoint
    _W_tmp="`winetricks_list_mounts "$1"`"
    if test "$_W_tmp"
    then
        _W_dev=`echo $_W_tmp | sed 's/ .*//'`
        _W_mountpoint="`echo $_W_tmp | sed 's/^[^ ]* //'`"
        # Volume found!
        return 0
    fi

    # If that fails, read volume name the hard way for each volume
    # Have to use file to return results from implicit subshell
    rm -f /tmp/_W_tmp.$LOGNAME
    winetricks_list_mounts . | while true
    do
        IFS= read _W_tmp

        _W_dev=`echo $_W_tmp | sed 's/ .*//'`
        test "$_W_dev" || break
        _W_mountpoint="`echo $_W_tmp | sed 's/^[^ ]* //'`"
        _W_volname=`winetricks_volname $_W_dev`
        if test "$1" = "$_W_volname"
        then
            # Volume found!  Want to return from function here, but can't
            echo "$_W_tmp" > /tmp/_W_tmp.$LOGNAME
            break
        fi
    done

    if test -f /tmp/_W_tmp.$LOGNAME
    then
        # Volume found!  Return from function.
        _W_dev=`cat /tmp/_W_tmp.$LOGNAME | sed 's/ .*//'`
        _W_mountpoint="`cat /tmp/_W_tmp.$LOGNAME | sed 's/^[^ ]* //'`"
        rm -f /tmp/_W_tmp.$LOGNAME
        return 0
    fi

    # Volume not found
    unset _W_dev _W_mountpoint _W_volname
    return 1
}

winetricks_mount_real_volume()
{
    _W_expected_volname="$1"

    # Wait for user to insert disc.

    case $LANG in
    da*)_W_mountmsg="Indsæt og montér venligst disken '$_W_expected_volname' (krævet af pakken '$_PACKAGE')" ;;
    de*)_W_mountmsg="Disc '$_W_expected_volname' bitte einlegen und montieren (für Pakete '$W_PACKAGE')" ;;
    *)  _W_mountmsg="Please insert and mount volume '$_W_expected_volname' (needed for package '$W_PACKAGE')" ;;
    esac

    if test "$WINE" = ""
    then
        w_die Windows not yet supported
    else
        while ! winetricks_is_mounted "$_W_expected_volname"
        do
            w_warn "$_W_mountmsg"
            # In non-gui case, give user two seconds to futz with disc drive before spamming him again
            sleep 2
        done
        WINETRICKS_DEV=$_W_dev
        W_ISO_MOUNT_ROOT="$_W_mountpoint"

        # Gotta provide a symlink to the raw disc, else installers that check volume names will fail
        rm -f "$WINEPREFIX/dosdevices/${W_ISO_MOUNT_LETTER}:"*
        ln -sf "$WINETRICKS_DEV" "$WINEPREFIX/dosdevices/${W_ISO_MOUNT_LETTER}::"
        ln -sf "$W_ISO_MOUNT_ROOT" "$WINEPREFIX/dosdevices/${W_ISO_MOUNT_LETTER}:"
    fi

    # FIXME: need to remount some discs with unhide option,
    # add that as option to w_mount

    unset _W_mountmsg
}

winetricks_cleanup()
{
    test "$WINETRICKS_CACHE_SYMLINK" && rm -f "$WINETRICKS_CACHE_SYMLINK"
    rm -rf "$WINETRICKS_WORKDIR"
}

winetricks_kill_handler()
{
    #echo "Caught signal, cleaning up."
    case "$WINETRICKS_DD_PID" in
    "") ;;
    *) kill $WINETRICKS_DD_PID ;;
    esac
    winetricks_cleanup
    #echo "Done cleanup, quitting."
    exit
}

winetricks_set_unattended()
{
    case $1 in
    1)
        W_OPT_UNATTENDED=1
        # Might want to trim our stable of variables here a bit...
        W_UNATTENDED_DASH_Q="-q"
        W_UNATTENDED_SLASH_Q="/q"
        W_UNATTENDED_SLASH_S="/S"
        W_UNATTENDED_DASH_SILENT="-silent"
        W_UNATTENDED_SLASH_SILENT="/silent"
        ;;
    *)
        W_OPT_UNATTENDED=0
        W_UNATTENDED_DASH_Q=""
        W_UNATTENDED_SLASH_Q=""
        W_UNATTENDED_SLASH_S=""
        W_UNATTENDED_DASH_SILENT=""
        W_UNATTENDED_SLASH_SILENT=""
        ;;
    esac
}

winetricks_init()
{
    #---- Private Variables ----

    # Ephemeral files for this run
    WINETRICKS_WORKDIR=/tmp/w.$LOGNAME.$$
    rm -rf "$WINETRICKS_WORKDIR"

    # Registering a verb creates a file in WINETRICKS_METADATA
    WINETRICKS_METADATA="$WINETRICKS_WORKDIR/metadata"

    # The list of categories is also hardcoded in winetricks_mainmenu() :-(
    WINETRICKS_CATEGORIES="apps benchmarks dlls fonts games settings"
    for _W_cat in $WINETRICKS_CATEGORIES
    do
        mkdir -p "$WINETRICKS_METADATA"/$_W_cat
    done
    WINETRICKS_COMMANDMENUS="run uninstall"

    # Which subdirectory of WINETRICKS_METADATA is currently active (or main, if none)
    WINETRICKS_CURMENU=main

    # Delete work directory after each run, on exit either graceful or abrupt
    trap winetricks_kill_handler 0 1 2 3 6

    # Which GUI helper to use (none/zenity/kdialog).  See winetricks_detect_gui.
    WINETRICKS_GUI=none

    # Whether to always cache cached iso's (1) or only use cache if present (0)
    # Can be inherited from environment or set via -k, defaults to off
    WINETRICKS_OPT_KEEPISOS=${WINETRICKS_OPT_KEEPISOS:-0}

    # what program to use to make disc image (dd or ddrescue)
    WINETRICKS_OPT_DD=${WINETRICKS_OPT_DD:-dd}

    # whether to use shared wineprefix (1) or unique wineprefix for each app (0)
    WINETRICKS_OPT_SHAREDPREFIX=${WINETRICKS_OPT_SHAREDPREFIX:-1}

    # Mac folks tend to not have sha1sum, but we can make do with openssl
    if [ -x "`which sha1sum 2>/dev/null`" ]
    then
       WINETRICKS_SHA1SUM="sha1sum"
    elif [ -x "`which openssl 2>/dev/null`" ]
    then
       WINETRICKS_SHA1SUM="openssl dgst -sha1"
    else
       w_die "No sha1sum utility available."
    fi

    # Which sourceforge mirror to use.  Rotate based on time, since
    # their mirror picker sometimes persistantly sends you to a broken
    # mirror.
    case `date +%S` in
    *[3])  WINETRICKS_SOURCEFORGE=http://easynews.dl.sourceforge.net/sourceforge ;;
    *)     WINETRICKS_SOURCEFORGE=http://downloads.sourceforge.net;;
    esac

    #---- Public Variables ----

    # System-specific variables
    case "$OS" in
     "Windows_NT")
        WINE=""
        W_DRIVE_C="C:/"
        ;;
     *)
        WINE=${WINE:-wine}
        WINEPREFIX="${WINEPREFIX:-$HOME/.wine}"
        W_DRIVE_C="$WINEPREFIX/dosdevices/c:"
        # This needs to go somewhere else soon, like ~/.local/wineprefixes
        W_PREFIXES_ROOT="${W_PREFIXES_ROOT:-$HOME/prefixes}"
        ;;
    esac
    # Verbs can rely on W_TMP being empty at entry, deleted after return, and a subdir of C:
    # Kludge: use _temp instead of temp to avoid \t expansion in w_try
    W_TMP="$W_DRIVE_C/windows/_temp"
    W_TMP_WIN="C:\\windows\\_temp"

    W_WINDIR_UNIX="$W_DRIVE_C/windows"

    # Where application installers are cached
    # See http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
    if test "$WINETRICKS_DIR"
    then
        W_CACHE="$WINETRICKS_DIR/cache"
    else
        WINETRICKS_DIR="$HOME/.local/winetricks"
        if test -d "$HOME/Library/Caches"
        then
            # MacOSX
            W_CACHE="$HOME/Library/Caches/winetricks"
        else
            XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
            W_CACHE="${W_CACHE:-$XDG_CACHE_HOME/winetricks}"
        fi
    fi
    test -d "$W_CACHE" || mkdir -p "$W_CACHE"
    # FIXME: move those tr's and sed's into w_pathconv, if they're still needed?
    W_CACHE_WIN="`w_pathconv -w $W_CACHE | tr '\012' ' ' | sed 's/ $//'`"

    # The folder-name is localized!
    W_PROGRAMS_WIN="`winetricks_early_wine cmd.exe /c echo "%ProgramFiles%" | tr -d '\015'`"
    case "$W_PROGRAMS_WIN" in
    "") w_die "$WINE cmd.exe /c echo '%ProgramFiles%' returned empty string" ;;
    %*) w_die "$WINE cmd.exe /c echo '%ProgramFiles%' returned unexpanded string... do you own the parent of $WINEPREFIX ?" ;;
    esac
    # FIXME: move that tr into w_pathconv, if it's still needed?
    W_PROGRAMS_UNIX="`w_pathconv -u "$W_PROGRAMS_WIN" | tr -d '\015' `"

    # 64 bit windows has a second directory for program files
    W_PROGRAMS_X86_WIN="${W_PROGRAMS_WIN} (x86)"
    W_PROGRAMS_X86_UNIX="${W_PROGRAMS_UNIX} (x86)"
    if ! test -d "$W_PROGRAMS_X86_UNIX"
    then
        W_PROGRAMS_X86_WIN="${W_PROGRAMS_WIN}"
        W_PROGRAMS_X86_UNIX="${W_PROGRAMS_UNIX}"
    fi

    W_APPDATA_WIN="`winetricks_early_wine cmd.exe /c echo "%AppData%" | tr -d '\015'`"
    W_APPDATA_UNIX="`w_pathconv -u "$W_APPDATA_WIN" | tr -d '\015' `"

    # FIXME: get fonts path from SHGetFolderPath
    # See also http://blogs.msdn.com/oldnewthing/archive/2003/11/03/55532.aspx
    W_FONTSDIR_WIN="c:\\windows\\Fonts"

    # FIXME: just convert path from windows to unix?
    # Did the user rename Fonts to fonts?
    if test ! -d "$W_WINDIR_UNIX"/Fonts && test -d "$W_WINDIR_UNIX"/fonts
    then
        W_FONTSDIR_UNIX="$W_WINDIR_UNIX"/fonts
    else
        W_FONTSDIR_UNIX="$W_WINDIR_UNIX"/Fonts
    fi
    mkdir -p "${W_FONTSDIR_UNIX}"

    # FIXME: don't hardcode
    W_PROGRAMS_DRIVE=c

    # Whether to automate installs (0=no, 1=yes)
    winetricks_set_unattended ${W_OPT_UNATTENDED:-0}

    case "$OS" in
    "Windows_NT")
        ;;
    *)
        # For case where z: doesn't exist or / is writable (!),
        # make a drive letter for W_CACHE.  Clean it up on exit.
        for letter in y x w v u t s r q p o n m
        do
            if ! test -d "$WINEPREFIX"/dosdevices/${letter}:
            then
                WINETRICKS_CACHE_SYMLINK="$WINEPREFIX"/dosdevices/${letter}:
                ln -sf "$W_CACHE" "$WINETRICKS_CACHE_SYMLINK"
                break
            fi
        done
    esac

    # Overridden for windows
    W_ISO_MOUNT_ROOT=/mnt/winetricks
    W_ISO_MOUNT_LETTER=i

    # Win(e) 32/64?
    # Using the variable W_SYSTEM32_DLLS instead of SYSTEM32 because some stuff does go under system32 for both arch's
    # e.g., spool/drivers/color
    if test -d "$W_DRIVE_C/windows/syswow64"
    then
        W_ARCH=win64
        W_SYSTEM32_DLLS="$W_WINDIR_UNIX/syswow64"
        W_SYSTEM32_DLLS_WIN="C:\\windows\\syswow64"
        W_SYSTEM64_DLLS="$W_WINDIR_UNIX/system32"
    else
        W_ARCH=win32
        W_SYSTEM32_DLLS="$W_WINDIR_UNIX/system32"
        W_SYSTEM32_DLLS_WIN="C:\\windows\\system32"
    fi
}

winetricks_usage()
{
    case $LANG in
    da*)
        cat <<_EOF_
Brug: $0 [tilvalg] [verbum|sti-til-verbum] ...
Kører de angivne verber.  Hvert verbum installerer et program eller ændrer en indstilling.
Tilvalg:
-k|--keep_isos: lagr iso'er lokalt (muliggør senere installation uden disk)
-q|--unattended: stil ingen spørgsmål, installér bare automatisk
-r|--ddrescue: brug alternativ disk-tilgangsmetode (hjælper i tilfælde af en ridset disk)
-v|--verbose: vis alle kommandoer som de bliver udført
-V|--version: vis programversionen og afslut
-h|--help: vis denne besked og afslut
Diverse verber:
list: vis en liste over alle verber
list-cached: vis en liste over verber for allerede-hentede installationsprogrammer
list-download: vis en liste over verber for programmer der kan hentes
list-manual-download: list applications which can be downloaded with some help from the user
list-installed: list already-installed applications
_EOF_
        ;;
    de*)
        cat <<_EOF_
Usage: $0 [options] [verb|path-to-verb] ...
Angegebene Verben ausführen.
Jeder Verb installiert z.B. eine Anwendung oder ändert eine Einstellung.
Optionen:
-k|--keep_isos: isos local speichern (erlaubt spätere Installierung ohne Disk)
-q|--unattended: keine Fragen stellen, alles automatisch installieren
-r|--ddrescue: alternative Zugriffsmodus (hilft bei gekratzten Disks)
-v|--verbose: alle ausgeführten Kommandos anzeigen
-V|--version: Programmversion anzeigen
-h|--help: diese Hilfemeldung anzeigen
Sonstige Verben:
apps: Typ 'Andwendungen' auswählen
games: Typ 'Spiele' auswählen
list: Verben von ausgewählte Typ auflisten
list-cached: Verben für schon gecachte Installers auflisten
list-download: Verben für herunterladbare Anwendungen auflisten
list-manual-download: list applications which can be downloaded with some help from the user
list-installed: Verben für schon installlierte Programme auflisten
_EOF_
        ;;
    *)
        cat <<_EOF_
Usage: $0 [options] [verb|path-to-verb] ...
Executes given verbs.  Each verb installs an application or changes a setting.
Options:
-k|--keep_isos: cache isos (allows later installation without disc)
-q|--unattended: don't ask any questions, just install automatically
-r|--ddrescue: alternate method of disc access (helps with scratched discs)
-v|--verbose: echo all commands as they are executed
-V|--version: display version and exit
-h|--help: display this message and exit
Miscellaneous verbs:
apps: select type 'apps'
games: select type 'games'
list: list verbs from selected category
list-cached: list cached-and-ready-to-install applications
list-download: list applications which can be downloaded automatically
list-manual-download: list applications which can be downloaded with some help from the user
list-installed: list already-installed applications
_EOF_
        ;;
    esac
}

winetricks_handle_option()
{
    case "$1" in
    -r|--ddrescue) WINETRICKS_OPT_DD=ddrescue ;;
    -k|--keep_isos) WINETRICKS_OPT_KEEPISOS=1 ;;
    -q|--unattended) winetricks_set_unattended 1 ;;
    -v|--verbose) set -x ;;
    -V|--version) winetricks_print_version ; exit 0;;
    -h|--help) winetricks_usage ; exit 0 ;;
    --optin) WINETRICKS_STATS_REPORT=1;;
    --optout) WINETRICKS_STATS_REPORT=0;;
    -*) w_die "unknown option $1" ;;
    *) return 1 ;;
    esac
    return 0
}

# Must initialize variables before calling w_metadata
if ! test "$WINETRICKS_LIB"
then
    WINETRICKS_SRCDIR=`dirname $0`
    WINETRICKS_SRCDIR=`cd $WINETRICKS_SRCDIR; /bin/pwd`

    # Handle options before init, to avoid starting wine for --help or --version
    while winetricks_handle_option $1
    do
        shift
    done

    winetricks_init
fi

winetricks_run_app()
{
    # Find the app
    case $WINETRICKS_OPT_SHAREDPREFIX in
    0)
        WINETRICKS_RUN_WINEPREFIX="$W_PREFIXES_ROOT"/$1
        app="$WINETRICKS_RUN_WINEPREFIX"/dosdevices/c:/run-$1.bat
        ;;
    1)
        WINETRICKS_RUN_WINEPREFIX="$WINEPREFIX"
        app="$W_DRIVE_C/run-$1.bat"
        ;;
    esac
    if ! test -f "$app"
    then
        w_die "Can't find app $1 (looked for $app)"
    fi
    WINEPREFIX="$WINETRICKS_RUN_WINEPREFIX" $WINE cmd /c C:\\run-$1.bat
}

winetricks_install_app()
{
    case $LANG in
    da*) fail_msg="Installationen af pakken $1 fejlede" ;;
    de*) fail_msg="Installieren von Pakete $1 gescheitert" ;;
    *)   fail_msg="Failed to install package $1" ;;
    esac

    # FIXME: initialize a new wineprefix for this app, set lots of global variables
    if ! w_do_call $1 $2
    then
        w_die "$fail_msg"
    fi
}

winetricks_uninstall_app()
{
    # Find the app
    case $WINETRICKS_OPT_SHAREDPREFIX in
    0)
        WINETRICKS_RUN_WINEPREFIX="$W_PREFIXES_ROOT"/$1
        app="$WINETRICKS_RUN_WINEPREFIX"/dosdevices/c:/run-$1.bat
        ;;
    1)
        w_die "Sorry, this tool can't uninstall apps from a shared wineprefix"
        ;;
    esac
    if ! test -f "$app"
    then
        w_die "Can't find app $1 (looked for $app)"
    fi
    rm -rf "$WINETRICKS_RUN_WINEPREFIX"
}

#---- Builtin Verbs ----

#----------------------------------------------------------------
# Runtimes
#----------------------------------------------------------------

#----- common download for several verbs

helper_directx_dl()
{
    # February 2010 DirectX 9c User Redistributable
    # http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=0cef8180-e94a-4f56-b157-5ab8109cb4f5
    # FIXME: none of the verbs that use this will show download status right
    # until file1 metadata is extended to handle common cache dir
    w_download directx9 http://download.microsoft.com/download/E/E/1/EE17FF74-6C45-4575-9CF4-7FC2597ACD18/directx_feb2010_redist.exe a97c820915dc20929e84b49646ec275760012a42

    DIRECTX_NAME=directx_feb2010_redist.exe
}

helper_d3dx9_xx()
{
    dllname=d3dx9_$1

    helper_directx_dl

    # Even kinder, less invasive directx - only extract and override d3dx9_xx.dll
    w_try_cabextract -d "$W_TMP" -L -F "*$dllname*x86*" "$W_CACHE"/directx9/$DIRECTX_NAME
    for x in "$W_TMP"/*.cab
    do
      w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F "$dllname.dll" "$x"
    done

    w_override_dlls native $dllname
}

#----------------------------------------------------------------

w_metadata  adobeair dlls \
   title="Adobe AIR 2.5.1" \
   publisher="Adobe" \
   year="2010" \
   media="download" \
   file1="AdobeAIRInstaller.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/Common Files/Adobe AIR/Versions/1.0/Adobe AIR.dll"

load_adobeair()
{
    # 2010-02-02: sha1sum 5c95f51a680f8c175a92755238127be4ad22c53b
    # 2010-02-20: sha1sum 6f03e723bd855abbe00eb8fdf22da54fb49c62db
    # 2010-07-29: 2.0.2 sha1sum 7b93aedaf48ad7854940e7a4e7d9394a255e888b
    # 2010-12-08: 2.1.5 sha1sum 2664207ca8e836f5070ee356064829a39785a92e
    w_download adobeair http://airdownload.adobe.com/air/win/download/2.5.1/AdobeAIRInstaller.exe 2664207ca8e836f5070ee356064829a39785a92e
    cd "$W_CACHE"/adobeair
    w_try $WINE AdobeAIRInstaller.exe $W_UNATTENDED_DASH_SILENT
}

#----------------------------------------------------------------

w_metadata amstream dlls \
   title="MS amstream.dll" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/amstream.dll"

load_amstream()
{
    helper_directx_dl
    mkdir "$W_CACHE"/amstream   # kludge so test -f $file1 works

    w_try_cabextract -d "$W_TMP" -L -F dxnt.cab "$W_CACHE"/directx9/$DIRECTX_NAME
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'amstream.dll' "$W_TMP/dxnt.cab"
    w_try_regsvr amstream.dll

    w_override_dlls native amstream
}

#----------------------------------------------------------------

w_metadata  art2kmin dlls \
   title="MS Access 2007 runtime" \
   publisher="Microsoft" \
   year="2007" \
   media="download" \
   file1="AccessRuntime.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/Common Files/Microsoft Shared/OFFICE12/ACEES.DLL"

load_art2kmin()
{
    # See http://www.microsoft.com/downloads/details.aspx?familyid=d9ae78d9-9dc6-4b38-9fa6-2c745a175aed&displaylang=en
    w_download art2kmin http://download.microsoft.com/download/D/2/A/D2A2FC8B-0447-491C-A5EF-E8AA3A74FB98/AccessRuntime.exe 571811b7536e97cf4e4e53bbf8260cddd69f9b2d
    cd "$W_CACHE"/art2kmin
    w_try $WINE AccessRuntime.exe $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata  atmlib dlls \
   title="Adobe Type Manager" \
   publisher="Adobe" \
   year="2009" \
   media="download" \
   file1="W2KSP4_EN.EXE" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/atmlib.dll"

load_atmlib()
{
    # http://www.microsoft.com/downloads/details.aspx?FamilyID=1001AAF1-749F-49F4-8010-297BD6CA33A0&displaylang=en
    # FIXME: This is a huge download for a single dll.
    # FIXME: This download is also used to get msasn1.dll, but we can't download into common cache directory until the file1 metadata download check is extended to handle that.  It'd be better to not need the huge download.
    w_download atmlib http://download.microsoft.com/download/E/6/A/E6A04295-D2A8-40D0-A0C5-241BFECD095E/W2KSP4_EN.EXE fadea6d94a014b039839fecc6e6a11c20afa4fa8
    cd "$W_TMP"
    w_try_cabextract "$W_CACHE"/atmlib/W2KSP4_EN.EXE i386/atmlib.dl_
    w_try cp atmlib.dll "$W_SYSTEM32_DLLS"
}

#----------------------------------------------------------------

w_metadata  comctl32 dlls \
   title="MS common controls 5.80" \
   publisher="Microsoft" \
   year="2001" \
   media="download" \
   file1="cc32inst.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/comctl32.dll"

load_comctl32()
{
    # http://www.microsoft.com/downloads/details.aspx?familyid=6f94d31a-d1e0-4658-a566-93af0d8d4a1e
    w_download comctl32 http://download.microsoft.com/download/platformsdk/redist/5.80.2614.3600/w9xnt4/en-us/cc32inst.exe 94c3c494258cc54bd65d2f0153815737644bffde

    w_try $WINE "$W_CACHE"/comctl32/cc32inst.exe "/T:$W_TMP_WIN" /c $W_UNATTENDED_SLASH_Q
    w_try_unzip -d "$W_TMP" "$W_TMP"/comctl32.exe
    w_try $WINE "$W_TMP"/x86/50ComUpd.Exe "/T:$W_TMP_WIN" /c $W_UNATTENDED_SLASH_Q
    w_try cp "$W_TMP"/comcnt.dll "$W_SYSTEM32_DLLS"/comctl32.dll

    w_override_dlls native,builtin comctl32

    # some builtin apps don't like native comctl32
    w_override_app_dlls winecfg.exe builtin comctl32
    w_override_app_dlls explorer.exe builtin comctl32
    w_override_app_dlls iexplore.exe builtin comctl32
}

#----------------------------------------------------------------

w_metadata  comdlg32ocx dlls \
   title="Common Dialog ActiveX Control for VB6" \
   publisher="Microsoft" \
   year="2009" \
   media="download" \
   file1="comdlg32.cab" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/comdlg32.ocx"

load_comdlg32ocx()
{
    # By analogy with vb5 version in http://support.microsoft.com/kb/168917
    w_download comdlg32ocx http://activex.microsoft.com/controls/vb6/comdlg32.cab d4f3e193c6180eccd73bad53a8500beb5b279cbf
    w_try_cabextract --directory="$W_TMP" "$W_CACHE"/comdlg32ocx/comdlg32.cab
    w_try cp "$W_TMP"/comdlg32.ocx "$W_SYSTEM32_DLLS"/comdlg32.ocx
    w_try_regsvr comdlg32.ocx
}

#----------------------------------------------------------------

w_metadata  crypt32 dlls \
   title="MS crypt32" \
   publisher="Microsoft" \
   year="2003" \
   media="download" \
   file1="Q823182_XPE_SP2_X86_ENU.EXE" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/crypt32.dll"

load_crypt32()
{
    w_call msasn1

    # https://www.microsoft.com/downloads/en/details.aspx?FamilyID=3d733ddd-1182-4d46-87c1-3357ca3fed28&DisplayLang=en
    w_download crypt32 http://download.microsoft.com/download/1/6/2/1629d13a-dc5e-4dc6-a2a4-a6784942b94e/Q823182_XPE_SP2_X86_ENU.EXE c3e0aa35ab5197ede0d495c0edc242cf0fade54a
    w_try_cabextract -d "$W_SYSTEM32_DLLS" "$W_CACHE"/crypt32/Q823182_XPE_SP2_X86_ENU.EXE -F rep/329115_crypt32.dll
    mv "$W_SYSTEM32_DLLS"/rep/329115_crypt32.dll "$W_SYSTEM32_DLLS"/crypt32.dll
    w_override_dlls native crypt32
}

#----------------------------------------------------------------

w_metadata d3dx9 dlls \
   title="MS d3dx9_??.dll from DirectX 9 redistributable" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/d3dx9_24.dll"

load_d3dx9()
{
    helper_directx_dl

    # Kinder, less invasive directx - only extract and override d3dx9_??.dll
    w_try_cabextract -d "$W_TMP" -L -F '*d3dx9*x86*' "$W_CACHE"/directx9/$DIRECTX_NAME
    for x in "$W_TMP"/*.cab
    do
      w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'd3dx9*.dll' "$x"
    done

    # For now, not needed, but when Wine starts preferring our builtin dll over native it will be.
    w_override_dlls native d3dx9_24 d3dx9_25 d3dx9_26 d3dx9_27 d3dx9_28 d3dx9_29 d3dx9_30
    w_override_dlls native d3dx9_31 d3dx9_32 d3dx9_33 d3dx9_34 d3dx9_35 d3dx9_36 d3dx9_37
    w_override_dlls native d3dx9_38 d3dx9_39 d3dx9_40 d3dx9_41 d3dx9_42 d3dx9_43
}

#----------------------------------------------------------------

w_metadata d3dx9_26 dlls \
   title="MS d3dx9_26.dll" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/d3dx9_26.dll"

load_d3dx9_26()
{
    helper_d3dx9_xx 26
}

#----------------------------------------------------------------

w_metadata d3dx9_28 dlls \
   title="MS d3dx9_28.dll" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/d3dx9_28.dll"

load_d3dx9_28()
{
    helper_d3dx9_xx 28
}

#----------------------------------------------------------------

w_metadata d3dx9_31 dlls \
   title="MS d3dx9_31.dll" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/d3dx9_31.dll"

load_d3dx9_31()
{
    helper_d3dx9_xx 31
}

#----------------------------------------------------------------

w_metadata d3dx9_35 dlls \
   title="MS d3dx9_35.dll" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/d3dx9_35.dll"

load_d3dx9_35()
{
    helper_d3dx9_xx 35
}

#----------------------------------------------------------------

w_metadata d3dx9_36 dlls \
   title="MS d3dx9_36.dll" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/d3dx9_36.dll"

load_d3dx9_36()
{
    helper_d3dx9_xx 36
}

#----------------------------------------------------------------

w_metadata d3dx9_42 dlls \
   title="MS d3dx9_42.dll" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/d3dx9_42.dll"

load_d3dx9_42()
{
    helper_d3dx9_xx 42
}

#----------------------------------------------------------------

w_metadata d3dx10 dlls \
   title="MS d3dx10_??.dll from DirectX user redistributable" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/d3dx10_33.dll"

load_d3dx10()
{
    helper_directx_dl

    # Kinder, less invasive directx10 - only extract and override d3dx10_??.dll
    w_try_cabextract -d "$W_TMP" -L -F '*d3dx10*x86*' "$W_CACHE"/directx9/$DIRECTX_NAME
    for x in "$W_TMP"/*.cab
    do
      w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'd3dx10*.dll' "$x"
    done

    # For now, not needed, but when Wine starts preferring our builtin dll over native it will be.
    w_override_dlls native d3dx10_33 d3dx10_34 d3dx10_35 d3dx10_36 d3dx10_37
    w_override_dlls native d3dx10_38 d3dx10_39 d3dx10_40 d3dx10_41 d3dx10_42
}

#----------------------------------------------------------------

w_metadata d3dxof dlls \
   title="MS d3dxof.dll from DirectX user redistributable" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/d3dxof.dll"

load_d3dxof()
{
    helper_directx_dl

    w_try_cabextract -d "$W_TMP" -L -F 'dxnt.cab' "$W_CACHE"/$DIRECTX_NAME
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'd3dxof.dll' "$W_TMP/dxnt.cab"

    w_override_dlls native d3dxof
}

#----------------------------------------------------------------

w_metadata devenum dlls \
   title="MS devenum.dll from DirectX user redistributable" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/devenum.dll"

load_devenum()
{
    helper_directx_dl

    w_try_cabextract -d "$W_TMP" -L -F 'dxnt.cab' "$W_CACHE/directx9/$DIRECTX_NAME"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'devenum.dll' "$W_TMP/dxnt.cab"
    w_try_regsvr devenum.dll
    w_override_dlls native devenum
}

#----------------------------------------------------------------

w_metadata dinput8 dlls \
   title="MS DirectInput 8 from DirectX user redistributable" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/dinput8.dll"

load_dinput8()
{
    helper_directx_dl

    w_try_cabextract -d "$W_TMP" -L -F 'dxnt.cab' "$W_CACHE"/directx9/$DIRECTX_NAME
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dinput8.dll' "$W_TMP/dxnt.cab"
    w_try_regsvr dinput8
    w_override_dlls native dinput8
}

#----------------------------------------------------------------

w_metadata directmusic dlls \
   title="MS DirectMusic from DirectX user redistributable" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/dmusic.dll"

load_directmusic()
{
# Untested. Based off http://bugs.winehq.org/show_bug.cgi?id=4805 and http://bugs.winehq.org/show_bug.cgi?id=24911
    helper_directx_dl

    w_try_cabextract -d "$W_TMP" -L -F dxnt.cab "$W_CACHE"/directx9/$DIRECTX_NAME
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'devenum.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dmband.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dmcompos.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dmime.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dmloader.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dmscript.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dmstyle.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dmsynth.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dmusic.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dmusic32.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dswave.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'streamci.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'quartz.dll' "$W_TMP/dxnt.cab"

    w_try_regsvr devenum.dll
    w_try_regsvr dmband.dll
    w_try_regsvr dmcompos.dll
    w_try_regsvr dmime.dll
    w_try_regsvr dmloader.dll
    w_try_regsvr dmscript.dll
    w_try_regsvr dmstyle.dll
    w_try_regsvr dmsynth.dll
    w_try_regsvr dmusic.dll
    w_try_regsvr dswave.dll
    w_try_regsvr quartz.dll

    w_override_dlls native devenum dmband dmcompos dmime dmloader dmscript dmstyle dmsynth dmusic dmusic32 dswave streamci quartz
}

#----------------------------------------------------------------

w_metadata directplay dlls \
   title="MS DirectPlay from DirectX user redistributable" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/dplayx.dll"

load_directplay()
{
    helper_directx_dl

    w_try_cabextract -d "$W_TMP" -L -F dxnt.cab "$W_CACHE"/directx9/$DIRECTX_NAME
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dplaysvr.exe' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dplayx.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dpnet.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dpnhpast.dll' "$W_TMP/dxnt.cab"
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dpwsockx.dll' "$W_TMP/dxnt.cab"

    w_try_regsvr dplayx.dll
    w_try_regsvr dpnet.dll
    w_try_regsvr dpnhpast.dll

    w_override_dlls native dplayx dpnet dpnhpast dpwsockx
}

#----------------------------------------------------------------

w_metadata directx9 dlls \
   title="MS DirectX 9" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/d3dx10_33.dll"

load_directx9()
{
    helper_directx_dl

    w_warn "You probably shouldn't be using this.  d3dx9 or, better, d3dx9_36 usually suffice."

    # Stefan suggested that, when installing, one should override as follows:
    # 1) use builtin wintrust (we don't run native properly somehow?)
    # 2) disable mscoree (else if it's present some module misbehaves?)
    # 3) override native any directx DLL whose Wine version doesn't register itself well yet
    # For #3, I have no idea which DLLs don't register themselves well yet,
    # so I'm just listing a few of the basic ones.  Let's whittle that
    # list down as soon as we can.

    # Setting windows version to win2k apparently crashes the installer on OS X.
    # See http://code.google.com/p/winezeug/issues/detail?id=71
    w_set_winver winxp

    cd "$W_CACHE"/directx9
    WINEDLLOVERRIDES="wintrust=b,mscoree=,ddraw,d3d8,d3d9,dsound,dinput=n" \
       w_try $WINE $DIRECTX_NAME /t:"$W_TMP_WIN" $W_UNATTENDED_SLASH_Q

    # How many of these do we really need?
    # We should probably remove most of these...?
    w_override_dlls native d3dim d3drm d3dx8 d3dx9_24 d3dx9_25 d3dx9_26 d3dx9_27 d3dx9_28 d3dx9_29
    w_override_dlls native d3dx9_30 d3dx9_31 d3dx9_32 d3dx9_33 d3dx9_34 d3dx9_35 d3dx9_36 d3dx9_37
    w_override_dlls native d3dx9_38 d3dx9_39 d3dx9_40 d3dx9_41 d3dx9_42 d3dx9_43 d3dxof
    w_override_dlls native dciman32 ddrawex devenum dmband dmcompos dmime dmloader dmscript dmstyle
    w_override_dlls native dmsynth dmusic dmusic32 dnsapi dplay dplayx dpnaddr dpnet dpnhpast dpnlobby
    w_override_dlls native dswave dxdiagn mscoree msdmo qcap quartz streamci
    w_override_dlls native dxdiag.exe
    w_override_dlls builtin d3d8 d3d9 dinput dinput8 dsound

    w_try $WINE "$W_TMP_WIN"\\DXSETUP.exe $W_UNATTENDED_SLASH_SILENT

    # reenable mscoree, or other installs may fail, see issue 25
    w_override_dlls builtin,native mscoree
}

#----------------------------------------------------------------

w_metadata dmsynth dlls \
   title="MS midi synthesizer from DirectX user redistributable" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/dplayx.dll"

load_dmsynth()
{
    helper_directx_dl

    w_try_cabextract -d "$W_TMP" -L -F dxnt.cab "$W_CACHE"/directx9/$DIRECTX_NAME
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dmsynth.dll' "$W_TMP/dxnt.cab"

    w_try_regsvr dmsynth.dll

    w_override_dlls native dmsynth
}

#----------------------------------------------------------------

w_metadata dotnet11 dlls \
   title="MS .NET 1.1" \
   publisher="Microsoft" \
   year="2003" \
   media="download" \
   file1="dotnetfx.exe" \
   installed_file1="c:/windows/Microsoft.NET/Framework/v1.1.4322/ndpsetup.ico"

load_dotnet11()
{
    if [ $W_ARCH = win64 ]
    then
        w_die "This package does not work on a 64-bit installation"
    fi

    w_call fontfix

    # http://www.microsoft.com/downloads/details.aspx?FamilyId=262D25E3-F589-4842-8157-034D1E7CF3A3
    w_download dotnet11 http://download.microsoft.com/download/a/a/c/aac39226-8825-44ce-90e3-bf8203e74006/dotnetfx.exe 16a354a2207c4c8846b617cbc78f7b7c1856340e

    # Remove bits of Wine that conflict with native .net 11
    rm -rf "$W_WINDIR_UNIX/Microsoft.NET/Framework/v1.1.4322"
    $WINE reg delete "HKLM\Software\Microsoft\.NETFramework\policy\v2.0" /f || true
    $WINE reg delete "HKLM\Software\Microsoft\.NETFramework" /v InstallRoot /f || true

    # need corefonts, else installer crashes
    w_call corefonts

    # Use builtin regsvcs.exe to work around http://bugs.winehq.org/show_bug.cgi?id=25120
    if test $W_OPT_UNATTENDED = 1
    then
        WINEDLLOVERRIDES="regsvcs.exe=b" w_try $WINE "$W_CACHE"/dotnet11/dotnetfx.exe /q /C:"install /q"
    else
        WINEDLLOVERRIDES="regsvcs.exe=b" w_try $WINE "$W_CACHE"/dotnet11/dotnetfx.exe
    fi
}

#----------------------------------------------------------------

w_metadata dotnet20 dlls \
   title="MS .NET 2.0" \
   publisher="Microsoft" \
   year="2006" \
   media="download" \
   file1="dotnetfx.exe" \
   installed_file1="c:/windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll"

load_dotnet20()
{
    w_call fontfix

    # Recipe from http://bugs.winehq.org/show_bug.cgi?id=10467#c57
    w_set_winver win2k
    # See http://kegel.com/wine/l_intl-sh.txt for how l_intl.nls was generated
    w_download dotnet20 http://kegel.com/wine/l_intl.nls 0d2e3f025bcdf852b192c9408a361ac2659fa249
    w_try cp -f "$W_CACHE"/dotnet20/l_intl.nls "$W_SYSTEM32_DLLS"

    # Remove bits of Wine that conflict with native .net 2.0
    $WINE reg delete "HKLM\Software\Microsoft\.NETFramework\policy\v2.0" /f || true
    $WINE reg delete "HKLM\Software\Microsoft\.NETFramework" /v InstallRoot /f || true

    # http://www.microsoft.com/downloads/details.aspx?FamilyID=0856eacb-4362-4b0d-8edd-aab15c5e04f5
    w_download dotnet20 http://download.microsoft.com/download/5/6/7/567758a3-759e-473e-bf8f-52154438565a/dotnetfx.exe a3625c59d7a2995fb60877b5f5324892a1693b2a
    if [ "$W_UNATTENDED_SLASH_Q"x = ""x ]
    then
       w_try $WINE "$W_CACHE"/dotnet20/dotnetfx.exe
    else
       w_try $WINE "$W_CACHE"/dotnet20/dotnetfx.exe /q /c:"install.exe /q"
    fi
    w_unset_winver

    # We can't stop installing dotnet20 in win2K mode until wine supports
    # reparse/junction points
    # (see http://bugs.winehq.org/show_bug.cgi?id=10467#c57 )
    # so for now just remove the bogus msvc*80.dll files it installs.
    # See also http://bugs.winehq.org/show_bug.cgi?id=16577
    # This affects Victoria 2 demo, see http://forum.paradoxplaza.com/forum/showthread.php?p=11523967
    rm -f "$W_SYSTEM32_DLLS"/msvc?80.dll
}

#----------------------------------------------------------------

w_metadata dotnet30 dlls \
   title="MS .NET 3.0" \
   publisher="Microsoft" \
   year="2006" \
   media="download" \
   file1="dotnetfx3.exe" \
   installed_file1="c:/windows/Microsoft.NET/Framework/v3.0/Microsoft .NET Framework 3.0/logo.bmp"

load_dotnet30()
{
    case "$OS" in
    "Windows_NT")
        osver=`cmd /c ver`
        case "$osver" in
        *Version?6*) w_die "Vista and up bundle .net 3.0, so you can't install it like this" ;;
        esac
        ;;
    esac

    w_call dotnet20

    w_warn "Installing .net 3.0 runtime takes 3 minutes on a very fast machine, and the Finished dialog may hide in the taskbar."
    # http://msdn.microsoft.com/en-us/netframework/bb264589.aspx
    w_download dotnet30 http://download.microsoft.com/download/3/F/0/3F0A922C-F239-4B9B-9CB0-DF53621C57D9/dotnetfx3.exe f3d2c3c7e4c0c35450cf6dab1f9f2e9e7ff50039

    # AF's workaround to avoid long pause
    LANGPACKS_BASE_PATH="${W_WINDIR_UNIX}/SYSMSICache/Framework/v3.0"
    test -d "${LANGPACKS_BASE_PATH}" || mkdir -p "${LANGPACKS_BASE_PATH}"
    for lang in ar cs da de el es fi fr he it jp ko nb nl pl pt-BR pt-PT ru \
                sv tr zh-CHS zh-CHT
    do
       ln -sf "${W_SYSTEM32_DLLS}/spupdsvc.exe" "${LANGPACKS_BASE_PATH}/dotnetfx3langpack${lang}.exe"
    done

    w_set_winver winxp

    cd "$W_CACHE"/dotnet30
    if [ "$W_UNATTENDED_SLASH_Q"x = ""x ]
    then
        w_try $WINE dotnetfx3.exe
    else
        w_try $WINE dotnetfx3.exe /q /c:"install.exe /q"
    fi
}

#----------------------------------------------------------------

w_metadata dotnet35 dlls \
   title="MS .NET 3.5" \
   publisher="Microsoft" \
   year="2007" \
   media="download" \
   file1="dotnetfx35.exe" \
   installed_file1="c:/windows/Microsoft.NET/Framework/v3.5/MSBuild.exe"

load_dotnet35()
{
    case "$OS" in
    "Windows_NT") ;;
    *) w_warn "dotnet35 does not yet fully work or install on wine.  Caveat emptor." ;;
    esac

    # According to AF's recipe, installing dotnet30 first works around msi bugs
    w_call dotnet30

    # http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6
    w_download dotnet35 http://download.microsoft.com/download/6/0/f/60fc5854-3cb8-4892-b6db-bd4f42510f28/dotnetfx35.exe

    # See also http://blogs.msdn.com/astebner/archive/2008/07/17/8745415.aspx
    cd "$W_TMP"
    w_try_cabextract $W_UNATTENDED_DASH_Q "$W_CACHE"/dotnet35/dotnetfx35.exe
    cd wcu/dotNetFramework
    $WINE dotNetFx35setup.exe /lang:ENU $W_UNATTENDED_SLASH_Q

    # FIXME: Do this only if the above commmand failed (not sure how to detect it... look for some file, I s'pose)
    if w_workaround_wine_bug 25060
    then
        # Thanks to Louis for this partial recipe
        #w_try $WINE reg add 'HKLM\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727' /v SP /t REG_DWORD /d 0001
        cat > "$W_TMP"/sp1.reg <<_EOF_
REGEDIT4

[HKEY_LOCAL_MACHINE\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727]
"SP"=dword:00000001

_EOF_
        w_try $WINE regedit "$W_TMP"/sp1.reg
        cd "$W_TMP"/wcu/dotNetFramework/dotNetFX35/x86
        w_try_cabextract netfx35_x86.exe
        w_try $WINE msiexec /i vs_setup.msi ADDEPLOY=1
    fi
}

#----------------------------------------------------------------

w_metadata dxdiagn dlls \
   title="DirectX Diagnostic Library" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/dxdiagn.dll"

load_dxdiagn()
{
    helper_directx_dl

    w_try_cabextract -d "$W_TMP" -L -F dxnt.cab "$W_CACHE"/directx9/$DIRECTX_NAME
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F dxdiagn.dll "$W_TMP/dxnt.cab"
    w_override_dlls native dxdiagn
}

#----------------------------------------------------------------

w_metadata dsound dlls \
   title="MS DirectSound from DirectX user redistributable" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/dsound.dll"

load_dsound()
{
    helper_directx_dl

    w_try_cabextract -d "$W_TMP" -L -F dxnt.cab "$W_CACHE"/directx9/$DIRECTX_NAME
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'dsound.dll' "$W_TMP/dxnt.cab"

    w_try_regsvr dsound.dll

    w_override_dlls native dsound
}

#----------------------------------------------------------------

# FIXME: update winetricks_is_installed to look at installed_file2
w_metadata flash dlls \
   title="Flash Player" \
   publisher="Adobe" \
   year="2010" \
   media="download" \
   file1="install_flash_player.exe" \
   file2="install_flash_player_ax.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/Macromed/Flash/FlashUtil10l_Plugin.exe" \
   installed_file2="$W_SYSTEM32_DLLS_WIN/Macromed/Flash/FlashUtil10l_ActiveX.exe"

load_flash()
{
    # www.adobe.com/products/flashplayer/

    # Active X plugin
    # http://blogs.adobe.com/psirt/2008/03/preparing_for_april_flash_play.html
    # http://fpdownload.macromedia.com/get/flashplayer/current/licensing/win/install_flash_player_active_x.msi
    # 2010-11-04: sha1sum 58412bcc83e349be50cafe0e1c46e19088620866
    w_download flash http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player_ax.exe 58412bcc83e349be50cafe0e1c46e19088620866
    cd "$W_CACHE"/flash

    if [ $W_UNATTENDED_SLASH_Q ]
    then
        w_try $WINE install_flash_player_ax.exe /install
    else
        w_try $WINE install_flash_player_ax.exe
    fi

    # Mozilla / Firefox plugin
    # 2010-11-04: sha1sum 09f2491c5bec7286155234f4e6e1af70c7cef78f
    w_download flash http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player.exe 09f2491c5bec7286155234f4e6e1af70c7cef78f
    if [ $W_UNATTENDED_SLASH_Q ]
    then
        w_try $WINE install_flash_player.exe /install
    else
        w_try $WINE install_flash_player.exe
    fi
}

#----------------------------------------------------------------

w_metadata gdiplus dlls \
   title="MS GDI+" \
   publisher="Microsoft" \
   year="2009" \
   media="download" \
   file1="WindowsXP-KB975337-x86-ENU.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/gdiplus.dll"

load_gdiplus()
{
    # FIXME: do newer versions of windows install a gdiplus in winsxs?
    # If so, and one is present, perhaps we should return without doing
    # anything here.

    # http://www.microsoft.com/downloads/details.aspx?familyid=6A63AB9C-DF12-4D41-933C-BE590FEAA05A&displaylang=en
    w_download gdiplus http://download.microsoft.com/download/a/b/c/abc45517-97a0-4cee-a362-1957be2f24e1/WindowsXP-KB975337-x86-ENU.exe b9a84bc3de92863bba1f5eb1d598446567fbc646
    # Used to use $W_UNATTENDED_SLASH_Q, but that mean that in non-q
    # mode, a mysterious "Extraction Complete" dialog was all user saw.
    # Showing that isn't useful, so always use /q.
    cd "$W_CACHE"/gdiplus
    w_try $WINE WindowsXP-KB975337-x86-ENU.exe /extract:$W_TMP_WIN /q
    # And then make it globally available.
    w_try cp "$W_TMP/asms/10/msft/windows/gdiplus/gdiplus.dll" "$W_SYSTEM32_DLLS"

    # For some reason, native,builtin isn't good enough...?
    w_override_dlls native gdiplus
}

#----------------------------------------------------------------

w_metadata gecko dlls \
   title="Gecko (not normally needed)" \
   publisher="Mozilla" \
   year="2010" \
   media="download"

load_gecko()
{
    if test -f /usr/share/wine/gecko/wine_gecko-1.0.0-x86.cab && test -f /usr/share/wine/gecko/wine_gecko-1.1.0-x86.cab
    then
        w_warn "gecko is already installed in /usr/share/wine"
    else
        w_warn "Please install gecko in /usr/share/wine per http://wiki.winehq.org/Gecko.  http://winezeug.googlecode.com/svn/trunk/install-gecko.sh is an easy script to do that.  Then you should never need to do 'winetricks gecko' again."
    fi
}

#----------------------------------------------------------------

w_metadata gecko110 dlls \
   title="Gecko 1.1.0 (not normally needed)" \
   publisher="Mozilla" \
   year="2010" \
   media="download" \
   file1="wine_gecko-1.1.0-x86.cab" \
   installed_file1="$W_SYSTEM32_DLLS/gecko/1.1.0/wine_gecko/nspr4.dll"

load_gecko110()
{
    w_skip_windows gecko110 && return

    w_warn "You should probably not be using the gecko110 verb, see http://wiki.winehq.org/Gecko"
    case `$WINE --version` in
    wine-0*|wine-1.[012]*|wine-1.3|wine-1.3.[01])
        w_die "This verb only supports wine-1.3.2 and higher at the moment"
        ;;
    esac

    w_download gecko110 "http://downloads.sourceforge.net/wine/wine_gecko-1.1.0-x86.cab" 1b6c637207b6f032ae8a52841db9659433482714 wine_gecko-1.1.0-x86.cab

    mkdir -p "$W_SYSTEM32_DLLS/gecko/1.1.0"
    cd "$W_SYSTEM32_DLLS/gecko/1.1.0"
    w_try_cabextract $W_UNATTENDED_DASH_Q "$W_CACHE/gecko110/wine_gecko-1.1.0-x86.cab"

    cat > "$W_TMP"/geckopath.reg <<_EOF_
REGEDIT4

[HKEY_CURRENT_USER\Software\Wine\MSHTML\1.1.0]
"GeckoPath"="c:\\\\windows\\\\system32\\\\gecko\\\\1.1.0\\\\wine_gecko\\\\"
_EOF_
    w_try_regedit "$W_TMP_WIN"\\geckopath.reg

    w_try_regsvr mshtml
}

#----------------------------------------------------------------

w_metadata  gfw dlls \
   title="MS Games For Windows Live (xlive.dll)" \
   publisher="Microsoft" \
   year="2008" \
   media="download" \
   file1="gfwlivesetupmin.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/xlive.dll"

load_gfw()
{
    # http://www.microsoft.com/games/en-us/live/pages/livejoin.aspx
    # http://www.next-gen.biz/features/should-games-for-windows-live-die
    w_download gfw http://download.microsoft.com/download/5/5/8/55846E20-4A46-4EF8-B272-7F988BC9090A/gfwlivesetupmin.exe 6f9e0ba052c68c8b51bb0e3ce6024d0e1c7b20b2  
    
    # FIXME: Depends on .Net 20, but is it really needed? For now, skip it.
    cd "$W_CACHE"/gfw
    w_try $WINE gfwlivesetupmin.exe /nodotnet $W_UNATTENDED_SLASH_Q

    w_call msasn1
}

#----------------------------------------------------------------

w_metadata  glut dlls \
   title="The glut utility library for OpenGL" \
   publisher="Mark J. Kilgard" \
   year="2001" \
   media="download" \
   file1="glut-3.7.6-bin.zip" \
   installed_file1="c:/glut-3.7.6-bin/glut32.lib"

load_glut()
{
    w_download glut http://www.xmission.com/~nate/glut/glut-3.7.6-bin.zip fb4731885c05b3cf2c79e85aabe8fc9949616ef4
    w_try_unzip -d "$W_DRIVE_C" "$W_CACHE"/glut/glut-3.7.6-bin.zip
    w_try cp "$W_DRIVE_C"/glut-3.7.6-bin/glut32.dll "$W_SYSTEM32_DLLS"
    w_warn "If you want to compile glut programs, add c:/glut-3.7.6-bin to LIB and INCLUDE"
}

#----------------------------------------------------------------
# um, codecs are kind of clustered here.  They probably deserve their own real category.

w_metadata allcodecs dlls \
   title="All codecs (dirac, ffdshow, icodecs, l3codecx, xvid) except wmp" \
   publisher="various" \
   year="1998-2009" \
   media="download"

load_allcodecs()
{
    w_call dirac
    w_call l3codecx
    w_call ffdshow
    w_call icodecs
    w_call xvid
}

#----------------------------------------------------------------

w_metadata dirac dlls \
   title="The Dirac directshow filter v1.0.2" \
   publisher="Dirac" \
   year="2009" \
   media="download" \
   file1="DiracDirectShowFilter-1.0.2.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/Dirac/DiracDecoder.dll"

load_dirac()
{
    w_download dirac $WINETRICKS_SOURCEFORGE/dirac/DiracDirectShowFilter-1.0.2.exe c912d30a8fa500c7841444559feb1f49301611c4

    # Avoid mfc90 not found error.  (DiracSplitter-libschroedinger.ax needs mfc90 to register itself, I think.)
    w_call vcrun2008

    cd "$W_CACHE"/dirac
    w_ahk_do "
        SetTitleMatchMode, 2
        run DiracDirectShowFilter-1.0.2.exe
        WinWait, Dirac, Welcome
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            ControlClick, Button2
            WinWait, Dirac, License
            ControlClick, Button2
            WinWait, Dirac, Location
            ControlClick, Button2
            WinWait, Dirac, Components
            ControlClick, Button2
            WinWait, Dirac, environment
            ControlCLick, Button1
            WinWait, Dirac, installed
            ControlClick, Button2
        }
        WinWaitClose
    "
}

#----------------------------------------------------------------

w_metadata ffdshow dlls \
   title="ffdshow video codecs" \
   publisher="doom9 folks" \
   year="2010" \
   media="download" \
   file1="ffdshow_beta7_rev3154_20091209.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/ffdshow/ff_liba52.dll" \
   homepage="http://ffdshow-tryout.sourceforge.net"

load_ffdshow()
{
    w_download ffdshow $WINETRICKS_SOURCEFORGE/ffdshow-tryout/ffdshow_beta7_rev3154_20091209.exe 8534c31489e51df70ee9583438d6211e6f0696d0
    cd "$W_CACHE"/ffdshow
    w_try $WINE ffdshow_beta7_rev3154_20091209.exe $W_UNATTENDED_SLASH_SILENT
}

#----------------------------------------------------------------

w_metadata icodecs dlls \
   title="Indeo codecs" \
   publisher="Intel" \
   year="1998" \
   media="download" \
   file1="codinstl.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/ir50_32.dll"

load_icodecs()
{
    # Note: this codec is insecure, see
    # http://support.microsoft.com/kb/954157
    # Original source, ftp://download.intel.com/support/createshare/camerapack/codinstl.exe, had same checksum
    w_download icodecs "http://codec.alshow.co.kr/Down/codinstl.exe" 2c5d64f472abe3f601ce352dcca75b4f02996f8a

    cd "$W_CACHE"/icodecs
    # FIXME: support unattended mode, possibly by scripting it with autohotkey
    w_try $WINE codinstl.exe

    # Work around bug in codec's installer?
    # http://support.britannica.com/other/touchthesky/win/issues/TSTUw_150.htm
    # http://appdb.winehq.org/objectManager.php?sClass=version&iId=7091
    w_try_regsvr ir50_32.dll
}

#----------------------------------------------------------------


w_metadata jet40 dlls \
   title="MS Jet 4.0 Service Pack 8" \
   publisher="Microsoft" \
   year="2003" \
   media="download" \
   file1="jet40sp8_9xnt.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/Common Files/Microsoft shared/dao/dao360.dll"

load_jet40()
{
    # http://support.microsoft.com/kb/239114
    # See also http://bugs.winehq.org/show_bug.cgi?id=6085
    # FIXME: "failed with error 2"
    w_download jet40 http://download.microsoft.com/download/4/3/9/4393c9ac-e69e-458d-9f6d-2fe191c51469/jet40sp8_9xnt.exe 8cd25342030857969ede2d8fcc34f3f7bcc2d6d4
    cd "$W_CACHE"/jet40
    w_try $WINE jet40sp8_9xnt.exe $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata kde apps \
    title="KDE on Windows" \
    publisher="various" \
    year="2011" \
    media="download" \
    file1="kdewin-installer-gui-0.9.8-1.exe" \
    installed_exe1="$W_PROGRAMS_UNIX/kde/etc/installer.ini" \
    homepage="http://windows.kde.org" \
    unattended="no"

load_kde()
{
    w_download kde http://www.winkde.org/pub/kde/ports/win32/installer/kdewin-installer-gui-0.9.8-1.exe b31aaf24d23b9f289bf56aa21e1571efc6bea58a

    mkdir -p "$W_PROGRAMS_UNIX/kde"
    w_try cp "$W_CACHE"/kde/kdewin-installer-gui-0.9.8-1.exe "$W_PROGRAMS_UNIX/kde"
    cd "$W_PROGRAMS_UNIX/kde"
    # There's no unattended option, probably because there are so many choices,
    # it's like cygwin
    w_try $WINE kdewin-installer-gui-0.9.8-1.exe
}

#----------------------------------------------------------------

w_metadata l3codecx dlls \
   title="MPEG Layer-3 Audio Codec for Microsoft DirectShow" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/l3codecx.ax"

load_l3codecx()
{
    helper_directx_dl

    w_try_cabextract -d "$W_TMP" -L -F dxnt.cab "$W_CACHE"/directx9/$DIRECTX_NAME
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'l3codecx.ax' "$W_TMP/dxnt.cab"

    w_try_regsvr l3codecx.ax
}

#----------------------------------------------------------------

w_metadata  mdac25 dlls \
   title="Microsoft Data Access Components 2.5 sp3" \
   publisher="Microsoft" \
   year="2002" \
   media="download" \
   file1="mdac_typ.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/Common Files/System/ADO/msado21.tlb"

load_mdac25()
{
    # http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c57692e9-dde7-4a60-b586-5d4fd6794db6
    w_download mdac25 http://download.microsoft.com/download/e/e/4/ee4fe9ee-6fa1-4ab6-ab8c-fe1769f4edcf/mdac_typ.exe 09e974a5dbebaaa08c7985a4a1126886dc05fd87
    load_native_mdac
    w_set_winver nt40
    if [ $W_UNATTENDED_SLASH_Q ]
    then
        w_try $WINE "$W_CACHE"/mdac25/mdac_typ.exe /q /C:"setup /QNT"
    else
        w_try $WINE "$W_CACHE"/mdac25/mdac_typ.exe
    fi
    w_unset_winver
}

#----------------------------------------------------------------

w_metadata  mdac27 dlls \
   title="Microsoft Data Access Components 2.7 sp1" \
   publisher="Microsoft" \
   year="2006" \
   media="download" \
   file1="mdac_typ.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/Common Files/System/ADO/msado26.tlb"

load_mdac27()
{
    # http://www.microsoft.com/downloads/en/details.aspx?FamilyId=9AD000F2-CAE7-493D-B0F3-AE36C570ADE8&displaylang=en
    w_download mdac27 http://download.microsoft.com/download/3/b/f/3bf74b01-16ba-472d-9a8c-42b2b4fa0d76/mdac_typ.exe f68594d1f578c3b47bf0639c46c11c5da161feee
    load_native_mdac
    w_set_winver win2k
    if [ $W_UNATTENDED_SLASH_Q ]
    then
        w_try $WINE "$W_CACHE"/mdac27/mdac_typ.exe /q /C:"setup /QNT"
    else
        w_try $WINE "$W_CACHE"/mdac27/mdac_typ.exe
    fi
    w_unset_winver
}

#----------------------------------------------------------------

w_metadata  mdac28 dlls \
   title="Microsoft Data Access Components 2.8" \
   publisher="Microsoft" \
   year="2003" \
   media="download" \
   file1="MDAC_TYP.EXE" \
   installed_file1="$W_PROGRAMS_X86_WIN/Common Files/System/ADO/msado27.tlb"

load_mdac28()
{
    # http://www.microsoft.com/downloads/en/details.aspx?FamilyID=6c050fe3-c795-4b7d-b037-185d0506396c
    w_download mdac28 http://download.microsoft.com/download/c/d/f/cdfd58f1-3973-4c51-8851-49ae3777586f/MDAC_TYP.EXE 91bd59f0b02b67f3845105b15a0f3502b9a2216a
    load_native_mdac
    w_set_winver win98
    cd "$W_CACHE"/mdac28
    if [ $W_UNATTENDED_SLASH_Q ]
    then
        w_try $WINE mdac_typ.exe /q /C:"setup /QNT"
    else
        w_try $WINE mdac_typ.exe
    fi
    w_unset_winver
}

#----------------------------------------------------------------

w_metadata  mfc40 dlls \
   title="MS mfc40 (Microsoft Foundation Classes from Visual C++ 4.0)" \
   publisher="Microsoft" \
   year="2004" \
   media="download" \
   file1="ole2v.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/MFC40.DLL"

load_mfc40()
{
    # See http://support.microsoft.com/kb/122244
    w_download mfc40 http://download.microsoft.com/download/ole/ole2v/3.5/w351/en-us/ole2v.exe c6cac71f32405ccb09c6f375e0738e6e13f073e4
    w_try_unzip -d "$W_TMP" "$W_CACHE"/mfc40/ole2v.exe
    w_try cp -f "$W_TMP"/MFC40.DLL "$W_SYSTEM32_DLLS"
}

#----------------------------------------------------------------

w_metadata mono26 dlls \
   title="Mono 2.6 (.NET compatability)" \
   publisher="Novell" \
   year="2009" \
   media="download" \
   file1="mono-2.6.7-gtksharp-2.12.10-win32-2.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/Mono-2.6.7/bin/mono.dll"

load_mono26()
{
    # Load Mono, have it handle all .net requests
    w_download mono26 http://ftp.novell.com/pub/mono/archive/2.6.7/windows-installer/2/mono-2.6.7-gtksharp-2.12.10-win32-2.exe c31c06063aa82006dff2f8df22dcc6ba046afbc2
    w_try $WINE "$W_CACHE"/mono26/mono-2.6.7-gtksharp-2.12.10-win32-2.exe $W_UNATTENDED_SLASH_SILENT
}

#----------------------------------------------------------------

w_metadata mono28 dlls \
   title="Mono 2.8 (.NET compatability)" \
   publisher="Novell" \
   year="2010" \
   media="download" \
   file1="mono-2.8.1-gtksharp-2.12.10-win32-3.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/Mono-2.8.1/bin/mono-2.0.dll"

load_mono28()
{
    # Load Mono, have it handle all .net requests
    w_download mono28 http://ftp.novell.com/pub/mono/archive/2.8.1/windows-installer/3/mono-2.8.1-gtksharp-2.12.10-win32-3.exe e491cbcadf486bdb3993efe6dc98e90c4e19425e
    w_try $WINE "$W_CACHE"/mono28/mono-2.8.1-gtksharp-2.12.10-win32-3.exe $W_UNATTENDED_SLASH_SILENT
}

#----------------------------------------------------------------

w_metadata mozillabuild apps \
    title="Mozilla build environment" \
    publisher="The Mozilla Foundation" \
    year="2010" \
    media="download" \
    file1="MozillaBuildSetup-1.5.1.exe" \
    installed_file1="$W_DRIVE_C/mozilla-build/start-l10n.bat" \
    homepage="https://wiki.mozilla.org/MozillaBuild"

load_mozillabuild()
{
    w_download mozillabuild http://ftp.mozilla.org/pub/mozilla.org/mozilla/libraries/win32/MozillaBuildSetup-1.5.1.exe 216c52eafe42df7559e8451f4e40a28e9c0f8133
    cd "$W_CACHE/$W_PACKAGE"
    w_try $WINE MozillaBuildSetup-1.5.1.exe $W_UNATTENDED_SLASH_S
}

#----------------------------------------------------------------

w_metadata msasn1 dlls \
   title="MS ASN1" \
   publisher="Microsoft" \
   year="2003" \
   media="download" \
   file1="W2KSP4_EN.EXE" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/msasn1.dll"

load_msasn1()
{
    # http://www.microsoft.com/downloads/details.aspx?FamilyID=1001AAF1-749F-49F4-8010-297BD6CA33A0&displaylang=en
    # FIXME: This is a huge download for a single dll.
    w_download msasn1 http://download.microsoft.com/download/E/6/A/E6A04295-D2A8-40D0-A0C5-241BFECD095E/W2KSP4_EN.EXE fadea6d94a014b039839fecc6e6a11c20afa4fa8
    cd "$W_TMP"
    w_try_cabextract -F i386/msasn1.dl_ "$W_CACHE"/msasn1/W2KSP4_EN.EXE
    w_try_cabextract i386/msasn1.dl_
    w_try cp msasn1.dll "$W_SYSTEM32_DLLS"
    w_try rm -rf i386
}

#----------------------------------------------------------------

w_metadata mshflxgd dlls \
   title="MS Hierarchical FlexGrid Control (mshflxgd.ocx)" \
   publisher="Microsoft" \
   year="2009" \
   media="download" \
   file1="MSHFLXGD.CAB" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/mshflxgd.ocx"

load_mshflxgd()
{
    # http://msdn.microsoft.com/en-us/library/aa240864(VS.60).aspx
    # orig: 5f9c7a81022949bfe39b50f2bbd799c448bb7377
    # Jan 2009: 7ad74e589d5eefcee67fa14e65417281d237a6b6
    # May 2009: bd8aa796e16e5f213414af78931e0379d9cbe292
    w_download mshflxgd http://activex.microsoft.com/controls/vb6/MSHFLXGD.CAB bd8aa796e16e5f213414af78931e0379d9cbe292

    w_try_cabextract --directory="$W_TMP" "$W_CACHE"/mshflxgd/MSHFLXGD.CAB
    w_try cp -f "$W_TMP"/[Mm][Ss][Hh][Ff][Ll][Xx][Gg][Dd].[Oo][Cc][Xx] "$W_SYSTEM32_DLLS"
    w_try_regsvr mshflxgd.ocx
}

#----------------------------------------------------------------

w_metadata msi2 dlls \
   title="Windows Installer 2.0" \
   publisher="Microsoft" \
   year="2001" \
   media="download" \
   file1="InstMsiA.exe" \
   installed_exe1="$W_SYSTEM32_DLLS_WIN/msiexec.exe"

load_msi2()
{
    # Install native msi per http://wiki.winehq.org/NativeMsi
    # http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=CEBBACD8-C094-4255-B702-DE3BB768148F
    w_download msi2 http://download.microsoft.com/download/WindowsInstaller/Install/2.0/W9XMe/EN-US/InstMsiA.exe e739c40d747e7c27aacdb07b50925b1635ee7366

    # Pick win98 so we can install native msi
    w_set_winver win98

    # Avoid "err:setupapi:SetupDefaultQueueCallbackA copy error 5 ..."
    rm -f "$W_SYSTEM32_DLLS"/msi.dll
    rm -f "$W_SYSTEM32_DLLS"/msiexec.exe

    cd "$W_CACHE"/msi2
    WINEDLLOVERRIDES="msi,msiexec.exe=n" w_try $WINE InstMSIA.exe $W_UNATTENDED_SLASH_Q

    w_override_dlls native,builtin msi msiexec.exe

    # and undo version win98
    w_unset_winver
}

#----------------------------------------------------------------

w_metadata msscript dlls \
   title="MS Windows Script Control" \
   publisher="Microsoft" \
   year="2004" \
   media="download" \
   file1="sct10en.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/msscript.ocx"

load_msscript()
{
    # http://msdn.microsoft.com/scripting/scriptcontrol/x86/sct10en.exe
    # http://www.microsoft.com/downloads/details.aspx?familyid=d7e31492-2595-49e6-8c02-1426fec693ac
    w_download msscript http://download.microsoft.com/download/d/2/a/d2a7430c-6d5b-48e9-96c4-3c751be7bffe/sct10en.exe fd9f2f23357ab11ae70682d6864f7e9f188adf2a

    w_try_cabextract --directory="$W_TMP" "$W_CACHE"/msscript/sct10en.exe
    w_try cp -f "$W_TMP"/msscript.ocx "$W_SYSTEM32_DLLS"
    w_try_regsvr msscript.ocx
}
#----------------------------------------------------------------

w_metadata msls31 dlls \
   title="MS Line Services" \
   publisher="Microsoft" \
   year="2001" \
   media="download" \
   file1="../msi2/InstMsiA.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/msls31.dll"

load_msls31()
{
    # Needed by native richedit and internet explorer
    w_download msi2 http://download.microsoft.com/download/WindowsInstaller/Install/2.0/W9XMe/EN-US/InstMsiA.exe e739c40d747e7c27aacdb07b50925b1635ee7366
    w_try_cabextract --directory="$W_TMP" "$W_CACHE"/msi2/InstMsiA.exe
    w_try cp -f "$W_TMP"/msls31.dll "$W_SYSTEM32_DLLS"
}

#----------------------------------------------------------------

w_metadata msmask dlls \
    title="MS Masked Edit Control" \
    publisher="Microsoft" \
    year="2009" \
    media="download" \
    file1="MSMASK32.CAB" \
    installed_file1="$W_SYSTEM32_DLLS/msmask32.ocx"

load_msmask()
{
    # http://msdn.microsoft.com/en-us/library/11405hcf(VS.71).aspx
    # http://bugs.winehq.org/show_bug.cgi?id=2934
    # old: 3c6b26f68053364ea2e09414b615dbebafb9d5c3
    # May 2009: 30e55679e4a13fe4d9620404476f215f93239292
    w_download msmask http://activex.microsoft.com/controls/vb6/MSMASK32.CAB 30e55679e4a13fe4d9620404476f215f93239292
    w_try_cabextract --directory="$W_TMP" "$W_CACHE"/msmask/MSMASK32.CAB
    w_try cp -f "$W_TMP"/[Mm][Ss][Mm][Aa][Ss][Kk]32.[Oo][Cc][Xx] "$W_SYSTEM32_DLLS"/msmask32.ocx
    w_try_regsvr msmask32.ocx
}

#----------------------------------------------------------------

w_metadata msxml3 dlls \
   title="MS XML Core Services 3.0" \
   publisher="Microsoft" \
   year="2005" \
   media="download" \
   file1="msxml3.msi" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/msxml3.dll"

load_msxml3()
{
    # Service Pack 5
    #w_download msxml3 http://download.microsoft.com/download/a/5/e/a5e03798-2454-4d4b-89a3-4a47579891d8/msxml3.msi
    # Service Pack 7
    w_download msxml3 http://download.microsoft.com/download/8/8/8/888f34b7-4f54-4f06-8dac-fa29b19f33dd/msxml3.msi d4c2178dfb807e1a0267fce0fd06b8d51106d913
    # it won't install on top of wine's msxml3, which has a pretty high version number, so delete wine's fake dll
    rm "$W_SYSTEM32_DLLS"/msxml3.dll
    w_override_dlls native msxml3
    cd "$W_CACHE"/msxml3
    w_try $WINE msiexec /i msxml3.msi $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata msxml4 dlls \
   title="MS XML Core Services 4.0" \
   publisher="Microsoft" \
   year="2009" \
   media="download" \
   file1="msxml.msi" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/msxml4.dll"

load_msxml4()
{
    # MS06-071: http://www.microsoft.com/downloads/details.aspx?familyid=24B7D141-6CDF-4FC4-A91B-6F18FE6921D4
    # w_download msxml4 http://download.microsoft.com/download/e/2/e/e2e92e52-210b-4774-8cd9-3a7a0130141d/msxml4-KB927978-enu.exe d364f9fe80c3965e79f6f64609fc253dfeb69c25
    # MS07-042: http://www.microsoft.com/downloads/details.aspx?FamilyId=021E12F5-CB46-43DF-A2B8-185639BA2807
    # w_download msxml4 http://download.microsoft.com/download/9/4/2/9422e6b6-08ee-49cb-9f05-6c6ee755389e/msxml4-KB936181-enu.exe 73d75d7b41f8a3d49f272e74d4f73bb5e82f1acf
    # SP3 (2009): http://www.microsoft.com/downloads/details.aspx?familyid=7F6C0CB4-7A5E-4790-A7CF-9E139E6819C0
    w_download msxml4 http://download.microsoft.com/download/A/2/D/A2D8587D-0027-4217-9DAD-38AFDB0A177E/msxml.msi aa70c5c1a7a069af824947bcda1d9893a895318b
    w_override_dlls native,builtin msxml4
    cd "$W_CACHE"/msxml4
    w_try $WINE msiexec /i msxml.msi $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata msxml6 dlls \
   title="MS XML Core Services 6.0 sp1" \
   publisher="Microsoft" \
   year="2007" \
   media="download" \
   file1="msxml6_x86.msi" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/msxml6.dll"

load_msxml6()
{
    # Service Pack 1
    # http://www.microsoft.com/downloads/details.aspx?familyid=D21C292C-368B-4CE1-9DAB-3E9827B70604
    w_download msxml6 http://download.microsoft.com/download/e/a/f/eafb8ee7-667d-4e30-bb39-4694b5b3006f/msxml6_x86.msi 5125220e985b33c946bbf9f60e2b222c7570bfa2
    w_override_dlls native,builtin msxml6
    rm -f "$W_SYSTEM32_DLLS/msxml6.dll"
    w_try $WINE msiexec /i "$W_CACHE"/msxml6/msxml6_x86.msi $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata ogg dlls \
   title="OpenCodecs 0.84: flac, speex, theora, vorbis, WebM" \
   publisher="xiph.org" \
   year="2010" \
   media="download" \
   file1="opencodecs_0.84.17338.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/Xiph.Org/Open Codecs/AxPlayer.dll" \
   homepage="http://xiph.org/dshow"

load_ogg()
{
    w_download ogg http://downloads.xiph.org/releases/oggdsf/opencodecs_0.84.17338.exe 6151ab79e6ae246208cdf707e080f01c93d95deb
    w_try $WINE "$W_CACHE"/ogg/opencodecs_0.84.17338.exe $W_UNATTENDED_SLASH_S
}

#----------------------------------------------------------------

w_metadata ole2 dlls \
   title="MS 16 bit OLE" \
   publisher="Microsoft" \
   year="1994" \
   media="download" \
   file1="ww1116.exe" \
   installed_file1="c:/windows/system/OLE2CONV.DLL"

load_ole2()
{
    # http://support.microsoft.com/kb/123087/EN-US/
    w_download ole2 http://download.microsoft.com/download/win31/update/2.03/win/en-us/ww1116.exe b803991c40f387464b61f606536b7c98a88245d2
    w_try_unzip -d "$W_TMP" "$W_CACHE"/ole2/ww1116.exe
    w_set_winver win31
    cd "$W_TMP"
    if w_workaround_wine_bug 25684
    then
        w_warn "The ole2 installer may hang at the end.  Please let me (dank@kegel.com) know whether it helps your app."
    fi
    w_try $WINE setup.exe
    w_unset_winver

    w_override_dlls native,builtin COMPOBJ OLE2CONV OLE2DISP OLE2 OLE2NLS OLE2PROX STORAGE TYPELIB
}

#----------------------------------------------------------------

w_metadata openwatcom apps \
    title="Open Watcom C/C++ compiler (can compile win16 code!)" \
    publisher="Watcom" \
    year="2010" \
    media="download" \
    file1="open-watcom-c-win32-1.9.exe" \
    installed_file1="$W_DRIVE_C/WATCOM/owsetenv.bat" \
    homepage="http://www.openwatcom.org"

load_openwatcom()
{
    w_download openwatcom "http://ftp.openwatcom.org/ftp/open-watcom-c-win32-1.9.exe" 236ac33ebd463006be4ecd83d7ebea1c026eb55a

    if [ $W_UNATTENDED_SLASH_Q ]
    then
        # Options documented at http://bugzilla.openwatcom.org/show_bug.cgi?id=898
        # But they don't seem to work on wine, so jam them into setup.inf
        # Pick smallest installation that supports 16 bit C and C++
        cd "$W_TMP"
        cp "$W_CACHE"/openwatcom/open-watcom-c-win32-1.9.exe .
        w_try_unzip open-watcom-c-win32-1.9.exe setup.inf
        sed -i 's/tools16=.*/tools16=true/' setup.inf
        w_try zip -f open-watcom-c-win32-1.9.exe
        w_try $WINE open-watcom-c-win32-1.9.exe -s
    else
        cd "$W_CACHE/$W_PACKAGE"
        w_try $WINE open-watcom-c-win32-1.9.exe
    fi

    if test ! -f "$W_DRIVE_C"/WATCOM/binnt/wcc.exe
    then
        w_warn "c:/watcom/binnt/wcc.exe not found; you probably didn't select 16 bit tools, and won't be able to buld win16test"
    fi
}

#----------------------------------------------------------------

w_metadata pdh dlls \
    title="MS pdh.dll (Performance Data Helper)" \
    publisher="Microsoft" \
    year="2001" \
    media="download" \
    file1="pdhinst.exe" \
    installed_file1="$W_SYSTEM32_DLLS/pdh.dll"

load_pdh()
{
    # http://support.microsoft.com/kb/284996
    w_download pdh http://download.microsoft.com/download/platformsdk/Redist/5.0.2195.2668/NT4/EN-US/pdhinst.exe f42448660def8cd7f42b34aa7bc7264745f4425e

    w_try_cabextract --directory="$W_TMP" "$W_CACHE"/pdh/pdhinst.exe
    w_try_unzip -d "$W_TMP" "$W_TMP"/pdh.exe
    w_try cp -f "$W_TMP"/x86/Pdh.Dll "$W_SYSTEM32_DLLS"/pdh.dll
}

#----------------------------------------------------------------

w_metadata physx dlls \
   title="PhysX" \
   publisher="NVidia" \
   year="2010" \
   media="download" \
   file1="PhysX_9.10.0129_SystemSoftware.exe" \
   installed_file1="$W_PROGRAMS_WIN/NVIDIA Corporation/PhysX/Engine/v2.8.3/PhysXCore.dll"

load_physx()
{
    # http://www.nvidia.com/object/physx_9.09.0814.html
    # w_download physx http://us.download.nvidia.com/Windows/9.09.0814/PhysX_9.09.0814_SystemSoftware.exe e19f7c3385a4a68e7acb85301bb4d2d0d1eaa1e2
    # http://www.nvidia.com/object/physx_9.10.0129.html
    w_download physx http://us.download.nvidia.com/Windows/9.10.0129/PhysX_9.10.0129_SystemSoftware.exe 33a8b54d842c7246946de15b1a48209c386c9c4b
    cd "$W_CACHE"/physx
    w_try $WINE PhysX_9.10.0129_SystemSoftware.exe $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata pngfilt dlls \
   title="pngfilt.dll (from ie6)" \
   publisher="Microsoft" \
   year="2002" \
   media="download" \
   file1="q328970.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/pngfilt.dll"

load_pngfilt()
{
    # http://support.microsoft.com/kb/328970
    w_download pngfilt http://download.microsoft.com/download/IE60/30secpac/6/W98NT42KMeXP/EN-US/q328970.exe 5fd84a335c43d194c0138a091dc0ea151ecc331c
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F pngfilt.dll "$W_CACHE"/pngfilt/q328970.exe
    w_try_regsvr pngfilt.dll
}

#----------------------------------------------------------------

w_metadata quartz dlls \
   title="quartz.dll (from Directx 9 user redistributable)" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/quartz.dll"

load_quartz()
{
    helper_directx_dl

    w_try_cabextract -d "$W_TMP" -L -F dxnt.cab "$W_CACHE"/directx9/$DIRECTX_NAME
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F quartz.dll "$W_TMP/dxnt.cab"

    w_try_regsvr quartz.dll

    w_override_dlls native quartz
}

#----------------------------------------------------------------

w_metadata quicktime72 dlls \
   title="Apple Quicktime 7.2" \
   publisher="Apple" \
   year="2010" \
   media="download" \
   file1="QuickTimeInstaller.exe" \
   installed_file1="c:/windows/Installer/{95A890AA-B3B1-44B6-9C18-A8F7AB3EE7FC}/QTPlayer.ico"

load_quicktime72()
{
    # http://www.apple.com/support/downloads/quicktime72forwindows.html
    w_download quicktime72 'http://wsidecar.apple.com/cgi-bin/nph-reg3rdpty2.pl/product=14402&cat=59&platform=osx&method=sa/QuickTimeInstaller.exe' bb89981f10cf21de57b9453e53cf81b9194271a9

    unset QUICKTIME_QUIET
    if test "$W_UNATTENDED_SLASH_Q" != ""
    then
       QUICKTIME_QUIET="/qn"  # ISSETUPDRIVEN=0
    fi

    if w_workaround_wine_bug 9366  # fixed in wine-1.1.22
    then
        w_call gdiplus
        w_call vcrun2005      # no bug number, but same era
    fi

    if w_workaround_wine_bug 1347
    then
        w_warn "Setting vista mode to avoid blacking the whole screen in quicktime"
        w_set_winver vista
    fi

    cd "$W_CACHE"/quicktime72
    w_try $WINE QuickTimeInstaller.exe ALLUSERS=1 DESKTOP_SHORTCUTS=0 QTTaskRunFlags=0 QTINFO.BISQTPRO=1 SCHEDULE_ASUW=0 REBOOT_REQUIRED=No $QUICKTIME_QUIET > /dev/null 2>&1

    if w_workaround_wine_bug 11681
    then
        # Following advice verified with test movies from 
        # http://support.apple.com/kb/HT1425
        # in QuickTimePlayer.

        w_warn "In Quicktime preferences, check Advanced / Safe Mode (gdi), or movies won't play."
        if test "$W_UNATTENDED_SLASH_Q" = ""
        then
            w_try $WINE control "$W_PROGRAMS_WIN\\QuickTime\\QTSystem\\QuickTime.cpl"
        else
            # FIXME: script the control panel with autohotkey?
            # We could probably also overwrite QuickTime.qtp but
            # the format isn't known, so we'd have to override all other settings, too.
            :
        fi
    fi
}
#----------------------------------------------------------------

w_metadata quicktime76 dlls \
   title="Apple Quicktime 7.6" \
   publisher="Apple" \
   year="2010" \
   media="download" \
   file1="QuickTimeInstaller.exe" \
   installed_file1="c:/windows/Installer/{57752979-A1C9-4C02-856B-FBB27AC4E02C}/QTPlayer.ico"

load_quicktime76()
{
    # http://www.apple.com/quicktime/download/
    w_download quicktime76 http://appldnld.apple.com/QuickTime/041-0025.20101207.Ptrqt/QuickTimeInstaller.exe 1eec8904f041d9e0ad3459788bdb690e45dbc38e

    unset QUICKTIME_QUIET
    if test "$W_UNATTENDED_SLASH_Q"
    then
       QUICKTIME_QUIET="/qn"  # ISSETUPDRIVEN=0
    fi

    if w_workaround_wine_bug 9366  # fixed in wine-1.1.22
    then
        w_call gdiplus
        w_call vcrun2005      # no bug number, but same era
    fi

    if w_workaround_wine_bug 1347
    then
        w_warn "Setting vista mode to avoid blacking the whole screen in quicktime"
        w_set_winver vista
    fi

    cd "$W_CACHE"/quicktime76
    w_try $WINE QuickTimeInstaller.exe ALLUSERS=1 DESKTOP_SHORTCUTS=0 QTTaskRunFlags=0 QTINFO.BISQTPRO=1 SCHEDULE_ASUW=0 REBOOT_REQUIRED=No $QUICKTIME_QUIET > /dev/null 2>&1

    if w_workaround_wine_bug 11681
    then
        # Following advice verified with test movies from 
        # http://support.apple.com/kb/HT1425
        # in QuickTimePlayer.

        w_warn "In Quicktime preferences, check Advanced / Safe Mode (gdi), or movies won't play."
        if test "$W_UNATTENDED_SLASH_Q" = ""
        then
            w_try $WINE control "$W_PROGRAMS_WIN\\QuickTime\\QTSystem\\QuickTime.cpl"
        else
            # FIXME: script the control panel with autohotkey?
            # We could probably also overwrite QuickTime.qtp but
            # the format isn't known, so we'd have to override all other settings, too.
            :
        fi
    fi
}
#----------------------------------------------------------------

w_metadata riched20 dlls \
   title="MS RichEdit Control version 2.0 (riched20.dll, riched32.dll)" \
   publisher="Microsoft" \
   year="1999" \
   media="download" \
   file1="Q249973i.EXE" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/riched20.dll"

load_riched20()
{
    # http://support.microsoft.com/?kbid=249973
    w_download riched20 http://download.microsoft.com/download/winntsp/Patch/RTF/NT4/EN-US/Q249973i.EXE f0b7663f15dbd31410435483ba832318c7a70470
    w_try_cabextract --directory="$W_TMP" "$W_CACHE"/riched20/Q249973i.EXE
    w_try cp -f "$W_TMP"/riched??.dll "$W_SYSTEM32_DLLS"
    w_override_dlls native,builtin riched20 riched32
}

#----------------------------------------------------------------

# Problem - riched20 and riched30 both install riched20.dll!
# We may need a better way to distinguish between installed files.

w_metadata riched30 dlls \
   title="MS RichEdit Control version 3.0 (riched20.dll, msls31.dll)" \
   publisher="Microsoft" \
   year="2001" \
   media="download" \
   file1="InstMsiA.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/riched20.dll" \
   installed_file2="$W_SYSTEM32_DLLS_WIN/msls31.dll"

load_riched30()
{
    # http://www.novell.com/documentation/nm1/readmeen_web/readmeen_web.html#Akx3j64
    # claims that Groupwise Messenger's View / Text Size command
    # only works with riched30, and recommends getting it by installing
    # msi 2, which just happens to come with riched30 version of riched20
    # (though not with a corresponding riched32, which might be a problem)
    # http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=CEBBACD8-C094-4255-B702-DE3BB768148F
    w_download riched30 http://download.microsoft.com/download/WindowsInstaller/Install/2.0/W9XMe/EN-US/InstMsiA.exe e739c40d747e7c27aacdb07b50925b1635ee7366
    w_try_cabextract --directory="$W_TMP" "$W_CACHE"/riched30/InstMsiA.exe
    w_try cp -f "$W_TMP"/riched20.dll "$W_SYSTEM32_DLLS"
    w_try cp -f "$W_TMP"/msls31.dll "$W_SYSTEM32_DLLS"
    w_override_dlls native,builtin riched30
}

#----------------------------------------------------------------

w_metadata richtx32 dlls \
   title="MS Rich TextBox Control 6.0" \
   publisher="Microsoft" \
   year="2009" \
   media="download" \
   file1="richtx32.cab" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/RichTx32.ocx"

load_richtx32()
{
    w_download richtx32 http://activex.microsoft.com/controls/vb6/richtx32.cab da404b566df3ad74fe687c39404a36c3e7cadc07
    w_try_cabextract "$W_CACHE"/richtx32/richtx32.cab -d "$W_SYSTEM32_DLLS" -F RichTx32.ocx
    w_try_regsvr RichTx32.ocx
}

#----------------------------------------------------------------

w_metadata secur32 dlls \
   title="MS Security Support Provider Interface" \
   publisher="Microsoft" \
   year="2009" \
   media="download" \
   file1="Windows2000-KB959426-x86-ENU.EXE" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/secur32.dll"

load_secur32()
{
    # http://www.microsoft.com/downloads/details.aspx?familyid=c4e408d7-6716-4a12-ad3a-8029667f5c84
    w_download secur32 http://download.microsoft.com/download/6/9/5/69501788-B62F-44D8-933F-B6FAA576CA87/Windows2000-KB959426-x86-ENU.EXE bf930a4d2982165a0793465bb255d494ba5b4cf7
    w_try_cabextract "$W_CACHE"/secur32/Windows2000-KB959426-x86-ENU.EXE -d "$W_SYSTEM32_DLLS" -F secur32.dll
    w_override_dlls native,builtin secur32
}

#----------------------------------------------------------------

w_metadata shockwave dlls \
   title="Shockwave" \
   publisher="Adobe" \
   year="2010" \
   media="download" \
   file1="sw_lic_full_installer.msi" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/Adobe/Shockwave 11/shockwave_Projector_Loader.dcr"

load_shockwave() {
    # Not silent enough, use msi instead
    #w_download shockwave http://fpdownload.macromedia.com/get/shockwave/default/english/win95nt/latest/Shockwave_Installer_Full.exe 840e34e9b067cf247bfa9092665b8966158f38e3
    #w_try $WINE "$W_CACHE"/Shockwave_Installer_Full.exe $W_UNATTENDED_SLASH_S
    # old sha1sum: 6a91a9da4b54c3fdc97130a15e1a173117e5f4ff
    # 2009-07-31 sha1sum: 0bb506ef67a268e8d3fb6c7ce556320ee10b9da5
    # 2009-12-13 sha1sum: d35649883bf13cb1a86f5650e1050d15533ac0f4
    # 2010-01-23 sha1sum: 4a837d238c28c5f345d73f105711f20c6d059273
    # 2010-05-15 sha1sum: bdce02afc82233801e84137e78c2c5fe574db253
    # 2010-09-02 sha1sum: fed20eccc29fec2f64162b7265343514d43884bc
    # 2010-11-03 sha1sum: 2ff28665543e80f3bd4ff1933ac05ec9314aaac6

    w_download shockwave http://fpdownload.macromedia.com/get/shockwave/default/english/win95nt/latest/sw_lic_full_installer.msi 2ff28665543e80f3bd4ff1933ac05ec9314aaac6
    cd "$W_CACHE"/shockwave
    w_try $WINE msiexec /i sw_lic_full_installer.msi $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata  usp10 dlls \
   title="Uniscribe 1.325 " \
   publisher="Microsoft" \
   year="2001" \
   media="download" \
   file1="../msi2/InstMsiA.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/usp10.dll"

load_usp10()
{
    # http://en.wikipedia.org/wiki/Uniscribe
    # http://www.microsoft.com/downloads/details.aspx?familyid=cebbacd8-c094-4255-b702-de3bb768148f
    w_download msi2 http://download.microsoft.com/download/WindowsInstaller/Install/2.0/W9XMe/EN-US/InstMsiA.exe e739c40d747e7c27aacdb07b50925b1635ee7366
    w_try_cabextract --directory="$W_TMP" "$W_CACHE"/msi2/InstMsiA.exe
    w_try cp -f "$W_TMP"/usp10.dll "$W_SYSTEM32_DLLS"
    w_override_dlls native,builtin usp10
}

#----------------------------------------------------------------

w_metadata  vb2run dlls \
   title="MS Visual Basic 2 runtime" \
   publisher="Microsoft" \
   year="1993" \
   media="download" \
   file1="VBRUN200.EXE" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/VBRUN200.DLL"

load_vb2run()
{
    # Not referenced on MS web anymore, but the old Microsoft Software Library FTP still has it.
    # See ftp://ftp.microsoft.com/Softlib/index.txt
    w_download vb2run ftp://ftp.microsoft.com/Softlib/MSLFILES/VBRUN200.EXE ac0568b73ee375408778e9b505df995f79ab907e
    w_try_unzip -d "$W_TMP" "$W_CACHE"/vb2run/VBRUN200.EXE
    w_try cp -f "$W_TMP/VBRUN200.DLL" "$W_SYSTEM32_DLLS"
}

#----------------------------------------------------------------

w_metadata  vb3run dlls \
   title="MS Visual Basic 3 runtime" \
   publisher="Microsoft" \
   year="1998" \
   media="download" \
   file1="vb3run.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/Vbrun300.dll"

load_vb3run()
{
    # See http://support.microsoft.com/kb/196285
    w_download vb3run http://download.microsoft.com/download/vb30/utility/1/w9xnt4/en-us/vb3run.exe 518fcfefde9bf680695cadd06512efadc5ac2aa7
    w_try_unzip -d "$W_TMP" "$W_CACHE"/vb3run/vb3run.exe
    w_try cp -f "$W_TMP/Vbrun300.dll" "$W_SYSTEM32_DLLS"
}

#----------------------------------------------------------------

w_metadata  vb4run dlls \
   title="MS Visual Basic 4 runtime" \
   publisher="Microsoft" \
   year="1998" \
   media="download" \
   file1="vb4run.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/Vb40032.dll"

load_vb4run()
{
    # See http://support.microsoft.com/kb/196286
    w_download vb4run http://download.microsoft.com/download/vb40ent/sample27/1/w9xnt4/en-us/vb4run.exe 83e968063272e97bfffd628a73bf0ff5f8e1023b
    w_try_unzip -d "$W_TMP" "$W_CACHE"/vb4run/vb4run.exe
    w_try cp -f "$W_TMP/Vb40032.dll" "$W_SYSTEM32_DLLS"
    w_try cp -f "$W_TMP/Vb40016.dll" "$W_SYSTEM32_DLLS"
}

#----------------------------------------------------------------

w_metadata  vb5run dlls \
   title="MS Visual Basic 5 runtime" \
   publisher="Microsoft" \
   year="2001" \
   media="download" \
   file1="msvbvm50.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/Msvbvm50.dll"

load_vb5run()
{
    w_download vb5run http://download.microsoft.com/download/vb50pro/utility/1/win98/en-us/msvbvm50.exe 28bfaf09b8ac32cf5ffa81252f3e2fadcb3a8f27
    cd "$W_CACHE"/vb5run
    w_try $WINE msvbvm50.exe $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata  vb6run dlls \
   title="MS Visual Basic 6 runtime sp6" \
   publisher="Microsoft" \
   year="2004" \
   media="download" \
   file1="vbrun60sp6.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/Msvbvm60.dll"

load_vb6run()
{
    # http://support.microsoft.com/kb/290887
    if test ! -f "$W_CACHE"/vb6run/vbrun60sp6.exe
    then
        w_download vb6run http://download.microsoft.com/download/5/a/d/5ad868a0-8ecd-4bb0-a882-fe53eb7ef348/VB6.0-KB290887-X86.exe 73ef177008005675134d2f02c6f580515ab0d842

        w_try $WINE "$W_CACHE"/vb6run/VB6.0-KB290887-X86.exe "/T:$W_TMP_WIN" /c $W_UNATTENDED_SLASH_Q
        if test ! -f "$W_TMP"/vbrun60sp6.exe
        then
            w_die vbrun60sp6.exe not found
        fi
        w_try mv "$W_TMP"/vbrun60sp6.exe "$W_CACHE"/vb6run
    fi

    # Delete some fake DLLs to ensure that the installer overwrites them.
    rm -f "$W_SYSTEM32_DLLS"/comcat.dll
    rm -f "$W_SYSTEM32_DLLS"/oleaut32.dll
    rm -f "$W_SYSTEM32_DLLS"/olepro32.dll
    rm -f "$W_SYSTEM32_DLLS"/stdole2.tlb

    cd "$W_CACHE"/vb6run
    # Exits with status 43 for some reason?
    $WINE vbrun60sp6.exe $W_UNATTENDED_SLASH_Q

    status=$?
    case $status in
    0|43) ;;
    *) w_die $W_PACKAGE installation failed
    esac
}

#----------------------------------------------------------------

w_metadata  vcrun6 dlls \
   title="Visual C++ 6 sp4 libraries (mfc42, msvcp60, msvcrt)" \
   publisher="Microsoft" \
   year="2000" \
   media="download" \
   file1="vc6redistsetup_enu.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/mfc42u.dll"

load_vcrun6()
{
    # Load the Visual C++ 6 runtime libraries, including the elusive mfc42u.dll

    if test ! -f "$W_CACHE"/vcrun6/vcredist.exe
    then
       w_download vcrun6 http://download.microsoft.com/download/vc60pro/update/1/w9xnt4/en-us/vc6redistsetup_enu.exe 382c8f5a7f41189af8d4165cf441f274b7e2a457

       w_try $WINE "$W_CACHE"/vcrun6/vc6redistsetup_enu.exe "/T:$W_TMP_WIN" /c $W_UNATTENDED_SLASH_Q
       if test ! -f "$W_TMP"/vcredist.exe
       then
          w_die vcredist.exe not found
       fi
       mv "$W_TMP"/vcredist.exe "$W_CACHE"/vcrun6
    fi
    # Delete some fake dlls to avoid vcredist installer warnings
    rm -f "$W_SYSTEM32_DLLS"/comcat.dll
    rm -f "$W_SYSTEM32_DLLS"/msvcrt.dll
    rm -f "$W_SYSTEM32_DLLS"/oleaut32.dll
    rm -f "$W_SYSTEM32_DLLS"/olepro32.dll
    rm -f "$W_SYSTEM32_DLLS"/stdole2.tlb
    $WINE "$W_CACHE"/vcrun6/vcredist.exe

    status=$?
    case $status in
    0|43) ;;
    *) w_die vcrun6 installation failed
    esac

    # And then some apps need mfc42u.dll, dunno what right way
    # is to get it, vcredist doesn't install it by default?
    w_try_cabextract "$W_CACHE"/vcrun6/vcredist.exe -d "$W_SYSTEM32_DLLS" -F mfc42u.dll

    w_override_dlls native,builtin msvcrt
}

w_metadata  mfc42 dlls \
   title="Visual C++ 6 sp4 mfc42 library (mfc42); same as vcrun6" \
   publisher="Microsoft" \
   year="2000" \
   media="download" \
   file1="../vcrun6/vc6redistsetup_enu.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/mfc42u.dll"

load_mfc42()
{
    w_call vcrun6
}

#----------------------------------------------------------------

# FIXME: we don't currently have an install check that can distinguish
# between sp4 and sp6, it would have to check size or version of a file,
# or maybe a registry key.

w_metadata  vcrun6sp6 dlls \
   title="Visual C++ 6 sp6 libraries (with fixes in atl and mfc)" \
   publisher="Microsoft" \
   year="2004" \
   media="download" \
   file1="Vs6sp6.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/mfc42u.dll"

load_vcrun6sp6()
{
    w_download vcrun6sp6 http://download.microsoft.com/download/1/9/f/19fe4660-5792-4683-99e0-8d48c22eed74/Vs6sp6.exe 2292437a8967349261c810ae8b456592eeb76620

    # No EULA is presented when passing command-line extraction arguments,
    # so we'll simplify extraction with cabextract.
    w_try_cabextract "$W_CACHE"/vcrun6sp6/Vs6sp6.exe -d "$W_TMP" -F vcredist.exe
    cd "$W_TMP"

    # Delete some fake dlls to avoid vcredist installer warnings
    w_try rm -f "$W_SYSTEM32_DLLS"/comcat.dll
    w_try rm -f "$W_SYSTEM32_DLLS"/msvcrt.dll
    w_try rm -f "$W_SYSTEM32_DLLS"/oleaut32.dll
    w_try rm -f "$W_SYSTEM32_DLLS"/olepro32.dll
    w_try rm -f "$W_SYSTEM32_DLLS"/stdole2.tlb
    # vcredist still exits with status 43.  Anyone know why?
    $WINE vcredist.exe

    status=$?
    case $status in
    0|43) ;;
    *) w_die $W_PACKAGE installation failed
    esac

    # And then some apps need mfc42u.dll, dunno what right way
    # is to get it, vcredist doesn't install it by default?
    w_try_cabextract vcredist.exe -d "$W_SYSTEM32_DLLS" -F mfc42u.dll

    w_override_dlls native,builtin msvcrt
}

#----------------------------------------------------------------

w_metadata  vcrun2003 dlls \
   title="Visual C++ 2003 libraries (mfc71,msvcp71,msvcr71)" \
   publisher="Microsoft" \
   year="2003" \
   media="download" \
   file1="BZEditW32_1.6.5_Installer.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/msvcp71.dll"

load_vcrun2003()
{
    # Load the Visual C++ 2003 runtime libraries
    # Sadly, I know of no Microsoft URL for these
    echo "Installing BZFlag (which comes with the Visual C++ 2003 runtimes)"
    w_download vcrun2003 $WINETRICKS_SOURCEFORGE/bzflag/BZEditW32_1.6.5_Installer.exe bdd1b32c4202fd77e6513fd507c8236888b09121
    w_try $WINE "$W_CACHE"/vcrun2003/BZEditW32_1.6.5_Installer.exe $W_UNATTENDED_SLASH_S
    w_try cp "$W_PROGRAMS_X86_UNIX/BZEdit1.6.5"/m*71* "$W_SYSTEM32_DLLS"
}

#----------------------------------------------------------------

w_metadata vcrun2005 dlls \
   title="Visual C++ 2005 libraries (mfc80,msvcp80,msvcr80)" \
   publisher="Microsoft" \
   year="2005" \
   media="download" \
   file1="vcredist_x86.exe" \
   installed_file1="c:/windows/winsxs/x86_Microsoft.VC80.MFC_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_b77cec8e/mfc80.dll"

load_vcrun2005()
{
    # SP1 + ATL security fix build 4053 (MS09-035)
    # See http://www.microsoft.com/downloads/details.aspx?familyid=766A6AF7-EC73-40FF-B072-9112BAB119C2
    w_download vcrun2005 http://download.microsoft.com/download/6/B/B/6BB661D6-A8AE-4819-B79F-236472F6070C/vcredist_x86.exe e052789ebad7dc8d6f8505a9295b0576babd125e
    cd "$W_CACHE"/vcrun2005
    w_override_dlls native,builtin msvcr80
    w_try $WINE vcredist_x86.exe $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata vcrun2008 dlls \
   title="Visual C++ 2008 libraries (mfc90,msvcp90,msvcr90)" \
   publisher="Microsoft" \
   year="2008" \
   media="download" \
   file1="vcredist_x86.exe" \
   installed_file1="C:/windows/winsxs/x86_Microsoft.VC90.MFC_1fc8b3b9a1e18e3b_9.0.30729.4148_x-ww_a57c1f53/mfc90.dll"

load_vcrun2008()
{
    # SP1 + ATL security fix build 4148 (MS09-035)
    # See http://www.microsoft.com/downloads/details.aspx?familyid=2051a0c1-c9b5-4b0a-a8f5-770a549fd78c
    w_download vcrun2008 http://download.microsoft.com/download/9/7/7/977B481A-7BA6-4E30-AC40-ED51EB2028F2/vcredist_x86.exe bd18409cfe75b88c2a9432d36d96f4bf125a3237
    w_override_dlls native,builtin msvcr90
    cd "$W_CACHE"/vcrun2008
    w_try $WINE vcredist_x86.exe $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata vcrun2010 dlls \
   title="Visual C++ 2010 libraries (mfc100,msvcp100,msvcr100)" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="vcredist_x86.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/mfc100.dll"

load_vcrun2010()
{
    # See http://www.microsoft.com/downloads/details.aspx?FamilyID=a7b7a05e-6de6-4d3a-a423-37bf0912db84
    w_download vcrun2010 http://download.microsoft.com/download/5/B/C/5BC5DBB3-652D-4DCE-B14A-475AB85EEF6E/vcredist_x86.exe 372d9c1670343d3fb252209ba210d4dc4d67d358

    if w_workaround_wine_bug 23427  # fixed in wine-1.3.5
    then
        w_call msxml3
    fi

    w_override_dlls native,builtin msvcr100
    cd "$W_CACHE"/vcrun2010
    w_try $WINE vcredist_x86.exe $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata vjrun20 dlls \
   title="MS Visual J# 2.0 SE libraries (requires dotnet20)" \
   publisher="Microsoft" \
   year="2007" \
   media="download" \
   file1="vjredist.exe" \
   installed_file1="$W_DRIVE_C/windows/Microsoft.NET/Framework/VJSHARP/VJSharpSxS10.dll"

load_vjrun20()
{
    if [ $W_ARCH = win64 ]
    then
        w_warn "vjrun20 depends on dotnet20, which doesn't work on 64-bit wine yet. Skipping."
        return
    fi

    w_call dotnet20

    # See http://www.microsoft.com/downloads/details.aspx?FamilyId=E9D87F37-2ADC-4C32-95B3-B5E3A21BAB2C
    w_download vjrun20 http://download.microsoft.com/download/9/2/3/92338cd0-759f-4815-8981-24b437be74ef/vjredist.exe 80a098e36b90d159da915aebfbfbacf35f302bd8

    if [ $W_UNATTENDED_SLASH_Q ]
    then
        w_try $WINE "$W_CACHE"/vjrun20/vjredist.exe /q /C:"install /QNT"
    else
        w_try $WINE "$W_CACHE"/vjrun20/vjredist.exe
    fi
}

#----------------------------------------------------------------

w_metadata windowscodecs dlls \
   title="MS Windows Imaging Component" \
   publisher="Microsoft" \
   year="2006" \
   media="download" \
   file1="wic_x86_enu.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/WindowsCodecs.dll"

load_windowscodecs()
{
    w_download windowscodecs http://download.microsoft.com/download/f/f/1/ff178bb1-da91-48ed-89e5-478a99387d4f/wic_x86_enu.exe 53c18652ac2f8a51303deb48a1b7abbdb1db427f

    # Avoid a file existence check.
    w_try rm -f "$W_SYSTEM32_DLLS"/windowscodecs.dll
    w_override_dlls native,builtin windowscodecs

    # Always run the WIC installer in passive mode.
    # See http://bugs.winehq.org/show_bug.cgi?id=16876 and
    # http://bugs.winehq.org/show_bug.cgi?id=23232
    cd "$W_CACHE/$W_PACKAGE"
    w_try $WINE wic_x86_enu.exe /passive
}

#----------------------------------------------------------------

w_metadata winhttp dlls \
   title="MS Windows HTTP Services" \
   publisher="Microsoft" \
   year="2005" \
   media="download" \
   file1="Windows2000-KB842773-x86-ENU.EXE" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/winhttp.dll"

load_winhttp()
{
    # See https://www.microsoft.com/downloads/en/details.aspx?FamilyID=3ee866a0-3a09-4fdf-8bdb-c906850ab9f2
    w_download winhttp http://download.microsoft.com/download/5/d/8/5d802926-6bab-45fa-b96e-bee15413523b/Windows2000-KB842773-x86-ENU.EXE e676d47e065a314bbf1d15b096a67aede6b0539a
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F winhttp.dll "$W_CACHE"/winhttp/Windows2000-KB842773-x86-ENU.EXE
    w_override_dlls native,builtin winhttp
}

#----------------------------------------------------------------

w_metadata wininet dlls \
   title="MS Windows Internet API" \
   publisher="Microsoft" \
   year="1999" \
   media="download" \
   file1="3725.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/wininet.dll"

load_wininet()
{
    # This is an updated wininet from IE 5.0.1.
    # (Good enough for Active Worlds browser.  Also helps "Avatar - Legends of the Arena" get to login screen.)
    # See http://www.microsoft.com/downloads/details.aspx?familyid=6DEE32AB-B618-4FB3-9A45-CDD08162E167
    w_download wininet http://download.microsoft.com/download/ie5/Update/1/WIN98/EN-US/3725.exe b048e0b4e303298de3317b16f7008c43ca71ddfe
    w_try_cabextract --directory="$W_TMP" "$W_CACHE/wininet/3725.exe"
    w_try cp -f "$W_TMP"/Wininet.dll "$W_SYSTEM32_DLLS"/wininet.dll
    w_override_dlls native,builtin wininet
}

#----------------------------------------------------------------

w_metadata wmi dlls \
   title="Windows Management Instrumentation (aka WBEM) Core 1.5" \
   publisher="Microsoft" \
   year="2000" \
   media="download" \
   file1="wmi9x.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/wbem/wbemcore.dll"

load_wmi()
{
    if test $W_ARCH = win64
    then
        w_die "Installer doesn't support 64-bit architecture."
    fi

    # WMI for NT4.0 need validation: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c174cfb1-ef67-471d-9277-4c2b1014a31e
    # See also http://www.microsoft.com/downloads/en/details.aspx?FamilyId=98A4C5BA-337B-4E92-8C18-A63847760EA5
    w_download wmi http://download.microsoft.com/download/platformsdk/wmi9x/1.5/W9X/EN-US/wmi9x.exe 62752e9c1b879688c26f205eebf07d3783906c3e

    w_set_winver win98
    w_override_dlls native,builtin wbemprox.dll wmiutils.dll
    # Note: there is a crash in the background towards the end, doesn't seem to hurt; see http://bugs.winehq.org/show_bug.cgi?id=7920
    cd "$W_CACHE"/wmi
    w_try $WINE wmi9x.exe $W_UNATTENDED_SLASH_S
    w_unset_winver
}

#----------------------------------------------------------------

w_metadata wsh56js dlls \
   title="MS Windows scripting 5.6, jscript only, no cscript" \
   publisher="Microsoft" \
   year="2006" \
   media="download" \
   file1="Windows2000-KB917344-56-x86-enu.exe" \
   installed_file1="$W_DRIVE_C/windows/inf/jscren.inf"

load_wsh56js()
{
    # This installs jscript 5.6 (but not vbscript)
    # See also http://www.microsoft.com/downloads/details.aspx?FamilyID=16dd21a1-c4ee-4eca-8b80-7bd1dfefb4f8&DisplayLang=en
    w_download wsh56js http://download.microsoft.com/download/b/c/3/bc3a0c36-fada-497d-a3de-8b0139766f3b/Windows2000-KB917344-56-x86-enu.exe add5f74c5bd4da6cfae47f8306de213ec6ed52c8

    cd "$W_CACHE/$W_PACKAGE"
    w_try $WINE Windows2000-KB917344-56-x86-enu.exe $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata wsh56vb dlls \
   title="MS Windows scripting 5.6, vbscript only, no cscript" \
   publisher="Microsoft" \
   year="2007" \
   media="download" \
   file1="vbs56men.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/vbscript.dll"

load_wsh56vb()
{
    # This installs vbscript 5.6 (but not jscript)
    # See also http://www.microsoft.com/downloads/details.aspx?familyid=4F728263-83A3-464B-BCC0-54E63714BC75
    w_download wsh56vb http://download.microsoft.com/download/IE60/Patch/Q318089/W9XNT4Me/EN-US/vbs56men.exe 48f14a93db33caff271da0c93f334971f9d7cb22

    cd "$W_CACHE"/wsh56vb
    w_try $WINE vbs56men.exe $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata wsh57 dlls \
   title="MS Windows Scripting Host 5.7" \
   publisher="Microsoft" \
   year="2007" \
   media="download" \
   file1="scripten.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/scrrun.dll"

load_wsh57()
{
    # See also http://www.microsoft.com/downloads/details.aspx?FamilyID=47809025-D896-482E-A0D6-524E7E844D81&displaylang=en
    w_download wsh57 http://download.microsoft.com/download/4/4/d/44de8a9e-630d-4c10-9f17-b9b34d3f6417/scripten.exe b15c6a834b7029e2dfed22127cf905b06857e6f5

    w_try_cabextract -d "$W_SYSTEM32_DLLS" "$W_CACHE"/wsh57/scripten.exe

    # Wine doesn't provide the other dll's (yet?)
    w_override_dlls native,builtin jscript.dll
    w_try_regsvr dispex.dll jscript.dll scrobj.dll scrrun.dll vbscript.dll wshcon.dll wshext.dll
}

#----------------------------------------------------------------

w_metadata xact dlls \
   title="MS XACT Engine" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/xactengine2_0.dll"

load_xact()
{
    helper_directx_dl

    # Extract xactengine?_?.dll, X3DAudio?_?.dll, xaudio?_?.dll, xapofx?_?.dll
    w_try_cabextract -d "$W_TMP" -L -F '*_xact_*x86*' "$W_CACHE"/directx9/$DIRECTX_NAME
    w_try_cabextract -d "$W_TMP" -L -F '*_x3daudio_*x86*' "$W_CACHE"/directx9/$DIRECTX_NAME
    w_try_cabextract -d "$W_TMP" -L -F '*_xaudio_*x86*' "$W_CACHE"/directx9/$DIRECTX_NAME
    for x in "$W_TMP"/*.cab
    do
      w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'xactengine*.dll' "$x"
      w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'xaudio*.dll' "$x"
    done

    # Register xactengine?_?.dll, xaudio?_?.dll
    for x in "$W_SYSTEM32_DLLS"/xactengine* "$W_SYSTEM32_DLLS"/xaudio*
    do
      w_try_regsvr `basename "$x"`
    done
}

#----------------------------------------------------------------

w_metadata xinput dlls \
   title="Microsoft XInput (Xbox controller support)" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/xinput1_1.dll"

load_xinput()
{
    helper_directx_dl

    w_try_cabextract -d "$W_TMP" -L -F '*_xinput_*x86*' "$W_CACHE"/directx9/$DIRECTX_NAME
    for x in "$W_TMP"/*.cab
    do
      w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F 'xinput*.dll' "$x"
    done
    w_try_regsvr xinput1_1.dll
    w_try_regsvr xinput1_2.dll
    w_try_regsvr xinput1_3.dll
    w_try_regsvr xinput9_1_0.dll
    w_override_dlls native xinput1_1
    w_override_dlls native xinput1_2
    w_override_dlls native xinput1_3
    w_override_dlls native xinput9_1_0
}

#----------------------------------------------------------------

w_metadata xmllite dlls \
    title="MS xmllite dll" \
    publisher="Microsoft" \
    year="2006" \
    media="download" \
    file1="WindowsXP-KB915865-v11-x86-ENU.exe" \
    installed_file1="$W_SYSTEM32_DLLS/xmllite.dll"

load_xmllite()
{
    w_download xmllite http://download.microsoft.com/download/f/9/6/f964059a-3747-4ed8-9326-ba1e639031b1/WindowsXP-KB915865-v11-x86-ENU.exe 226d246a1c64e693791de5c727509002d089b0d5

    if w_workaround_wine_bug 16013
    then
        # Find instructions to create this file in dlls/wintrust/tests/crypt.c
        w_download xmllite http://winezeug.googlecode.com/svn/trunk/winetricks_files/winetest.cat ac8f50dd54d011f3bb1dd79240dae9378748449f
        # Put a dummy catalog file in place
        mkdir -p "$W_SYSTEM32_DLLS"/catroot/\{f750e6c3-38ee-11d1-85e5-00c04fc295ee\}
        w_try cp -f "$W_CACHE"/xmllite/winetest.cat "$W_SYSTEM32_DLLS"/catroot/\{f750e6c3-38ee-11d1-85e5-00c04fc295ee\}/oem0.cat
        if test $W_OPT_UNATTENDED != 1
        then
            w_warn "xmllite's interactive installer will hang at the end, but otherwise work."
        fi
    fi

    cd "$W_CACHE"/xmllite
    w_override_dlls native xmllite
    w_try $WINE WindowsXP-KB915865-v11-x86-ENU.exe $W_UNATTENDED_SLASH_Q
}

#----------------------------------------------------------------

w_metadata  xvid dlls \
    title="Xvid Video Codec" \
    publisher="xvid.org" \
    year="2009" \
    media="download" \
    file1="Xvid-1.2.2-07062009.exe" \
    installed_file1="$W_PROGRAMS_X86_WIN/Xvid/xvid.ico"

load_xvid()
{
    w_call vcrun6
    w_download xvid http://www.koepi.info/Xvid-1.2.2-07062009.exe 435203e7f713c4484ca4f50f43e847f3dc118962
    cd "$W_CACHE"/xvid
    w_try $WINE Xvid-1.2.2-07062009.exe $W_UNATTENDED_SLASH_SILENT
}

#----------------------------------------------------------------
# Fonts
#----------------------------------------------------------------

w_metadata baekmuk fonts \
   title="Baekmuk Korean fonts" \
   publisher="Wooderart Inc. / kldp.net" \
   year="1999" \
   media="download" \
   file1="ttf-baekmuk_2.2.orig.tar.gz" \
   installed_file1="$W_FONTSDIR_WIN/batang.ttf"

load_baekmuk()
{
    # See http://kldp.net/projects/baekmuk for project page
    # Need to download from Debian as the project page has unique captcha tokens per visitor
    w_download baekmuk http://ftp.debian.org/debian/pool/main/t/ttf-baekmuk/ttf-baekmuk_2.2.orig.tar.gz afdee34f700007de6ea87b43c92a88b7385ba65b
    cd "$W_TMP/"
    gunzip -dc "$W_CACHE/baekmuk/ttf-baekmuk_2.2.orig.tar.gz" | tar -xf -
    w_try mv baekmuk-ttf-2.2/ttf/*.ttf "$W_FONTSDIR_UNIX"
    w_register_font batang.ttf "Baekmuk Batang"
    w_register_font gulim.ttf "Baekmuk Gulim"
    w_register_font dotum.ttf "Baekmuk Dotum"
    w_register_font hline.ttf "Baekmuk Headline"
}

#----------------------------------------------------------------

w_metadata cjkfonts fonts \
   title="All Chinese, Japanese, Korean fonts and aliases" \
   publisher="various" \
   date="1999-2010" \
   media="download"

load_cjkfonts()
{
    w_call fakechinese
    w_call fakejapanese
    w_call fakekorean
    w_call unifont
}

#----------------------------------------------------------------

w_metadata corefonts fonts \
   title="MS Arial, Courier, Times fonts" \
   publisher="Microsoft" \
   year="2008" \
   media="download" \
   file1="arial32.exe" \
   installed_file1="$W_FONTSDIR_WIN/Arial.TTF"

load_corefonts()
{
    # See http://corefonts.sf.net
    # TODO: let user pick mirror,
    # see http://corefonts.sourceforge.net/msttcorefonts-2.0-1.spec for how
    # TODO: add more fonts

    # Added More Fonts (see msttcorefonts)
    # [*] Pointed w_download locations to sites that actually contained the
    # fonts to w_download (as of 04-03-2008)
    #w_download corefonts $WINETRICKS_SOURCEFORGE/corefonts/andale32.exe c4db8cbe42c566d12468f5fdad38c43721844c69
    w_download corefonts $WINETRICKS_SOURCEFORGE/corefonts/arial32.exe 6d75f8436f39ab2da5c31ce651b7443b4ad2916e
    w_download corefonts $WINETRICKS_SOURCEFORGE/corefonts/arialb32.exe d45cdab84b7f4c1efd6d1b369f50ed0390e3d344
    w_download corefonts $WINETRICKS_SOURCEFORGE/corefonts/comic32.exe 2371d0327683dcc5ec1684fe7c275a8de1ef9a51
    w_download corefonts $WINETRICKS_SOURCEFORGE/corefonts/courie32.exe 06a745023c034f88b4135f5e294fece1a3c1b057
    w_download corefonts $WINETRICKS_SOURCEFORGE/corefonts/georgi32.exe 90e4070cb356f1d811acb943080bf97e419a8f1e
    w_download corefonts $WINETRICKS_SOURCEFORGE/corefonts/impact32.exe 86b34d650cfbbe5d3512d49d2545f7509a55aad2
    w_download corefonts $WINETRICKS_SOURCEFORGE/corefonts/times32.exe 20b79e65cdef4e2d7195f84da202499e3aa83060
    w_download corefonts $WINETRICKS_SOURCEFORGE/corefonts/trebuc32.exe 50aab0988423efcc9cf21fac7d64d534d6d0a34a
    w_download corefonts $WINETRICKS_SOURCEFORGE/corefonts/verdan32.exe f5b93cedf500edc67502f116578123618c64a42a
    w_download corefonts $WINETRICKS_SOURCEFORGE/corefonts/webdin32.exe 2fb4a42c53e50bc70707a7b3c57baf62ba58398f

    # Natively installed versions of these fonts will cause the installers
    # to exit silently. Because there are apps out there that depend on the
    # files being present in the Windows font directory we use cabextract
    # to obtain the files and register the fonts by hand.

    # Andale needs a FontSubstitutes entry
    # w_try_cabextract --directory="$W_TMP" "$W_CACHE"/corefonts/andale32.exe

    # Display EULA
    test x"$W_UNATTENDED_SLASH_Q" = x"" || w_try $WINE "$W_CACHE"/corefonts/arial32.exe $W_UNATTENDED_SLASH_Q

    w_try_cabextract -q --directory="$W_TMP" "$W_CACHE"/corefonts/arial32.exe
    w_try cp -f "$W_TMP"/Arial*.TTF "$W_FONTSDIR_UNIX"
    w_register_font Arial.TTF "Arial"
    w_register_font Arialbd.TTF "Arial Bold"
    w_register_font Arialbi.TTF "Arial Bold Italic"
    w_register_font Ariali.TTF "Arial Italic"

    w_try_cabextract -q --directory="$W_TMP" "$W_CACHE"/corefonts/arialb32.exe
    w_try cp -f "$W_TMP"/AriBlk.TTF "$W_FONTSDIR_UNIX"
    w_register_font AriBlk.TTF "Arial Black"

    w_try_cabextract -q --directory="$W_TMP" "$W_CACHE"/corefonts/comic32.exe
    w_try cp -f "$W_TMP"/Comic*.TTF "$W_FONTSDIR_UNIX"
    w_register_font Comic.TTF "Comic Sans MS"
    w_register_font Comicbd.TTF "Comic Sans MS Bold"

    w_try_cabextract -q --directory="$W_TMP" "$W_CACHE"/corefonts/courie32.exe
    w_try cp -f "$W_TMP"/cour*.ttf "$W_FONTSDIR_UNIX"
    w_register_font Cour.TTF "Courier New"
    w_register_font CourBD.TTF "Courier New Bold"
    w_register_font CourBI.TTF "Courier New Bold Italic"
    w_register_font Couri.TTF "Courier New Italic"

    w_try_cabextract -q --directory="$W_TMP" "$W_CACHE"/corefonts/georgi32.exe
    w_try cp -f "$W_TMP"/Georgia*.TTF "$W_FONTSDIR_UNIX"
    w_register_font Georgia.TTF "Georgia"
    w_register_font Georgiab.TTF "Georgia Bold"
    w_register_font Georgiaz.TTF "Georgia Bold Italic"
    w_register_font Georgiai.TTF "Georgia Italic"

    w_try_cabextract -q --directory="$W_TMP" "$W_CACHE"/corefonts/impact32.exe
    w_try cp -f "$W_TMP"/Impact.TTF "$W_FONTSDIR_UNIX"
    w_register_font Impact.TTF "Impact"

    w_try_cabextract -q --directory="$W_TMP" "$W_CACHE"/corefonts/times32.exe
    w_try cp -f "$W_TMP"/Times*.TTF "$W_FONTSDIR_UNIX"
    w_register_font Times.TTF "Times New Roman"
    w_register_font Timesbd.TTF "Times New Roman Bold"
    w_register_font Timesbi.TTF "Times New Roman Bold Italic"
    w_register_font Timesi.TTF "Times New Roman Italic"

    w_try_cabextract -q --directory="$W_TMP" "$W_CACHE"/corefonts/trebuc32.exe
    w_try cp -f "$W_TMP"/trebuc*.ttf "$W_FONTSDIR_UNIX"
    w_register_font Trebuc.TTF "Trebucet MS"
    w_register_font Trebucbd.TTF "Trebucet MS Bold"
    w_register_font Trebucbi.TTF "Trebucet MS Bold Italic"
    w_register_font Trebucit.TTF "Trebucet MS Italic"

    w_try_cabextract -q --directory="$W_TMP" "$W_CACHE"/corefonts/verdan32.exe
    w_try cp -f "$W_TMP"/Verdana*.TTF "$W_FONTSDIR_UNIX"
    w_register_font Verdana.TTF "Verdana"
    w_register_font Verdanab.TTF "Verdana Bold"
    w_register_font Verdanaz.TTF "Verdana Bold Italic"
    w_register_font Verdanai.TTF "Verdana Italic"

    w_try_cabextract -q --directory="$W_TMP" "$W_CACHE"/corefonts/webdin32.exe
    w_try cp -f "$W_TMP"/Webdings.TTF "$W_FONTSDIR_UNIX"
    w_register_font Webdings.TTF "Webdings"
}

#----------------------------------------------------------------

w_metadata droid fonts \
   title="Droid fonts" \
   publisher="Ascender Corporation" \
   year="2009" \
   media="download" \
   file1="DroidSans-Bold.ttf" \
   installed_file1="$W_FONTSDIR_WIN/DroidSans-Bold.ttf"

do_droid() {
    w_download droid ${DROID_URL}$1';hb=HEAD'   $3  $1
    w_try cp -f "$W_CACHE"/droid/$1 "$W_FONTSDIR_UNIX"
    w_register_font $1 "$2"
}

load_droid()
{
    # See http://en.wikipedia.org/wiki/Droid_(font)
    DROID_URL='http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob_plain;f=data/fonts/'

    do_droid DroidSans-Bold.ttf        "Droid Sans Bold"         ada4e79c592f3c54546b7587b48f2b232d95ce2f
    do_droid DroidSansFallback.ttf     "Droid Sans Fallback"     5065cce92e8420232db95ab3ba421e462b09b965
    do_droid DroidSansJapanese.ttf     "Droid Sans Japanese"     b3a248c11692aa88a30eb25df425b8910fe05dc5
    do_droid DroidSansMono.ttf         "Droid Sans Mono"         f0815c6f36c72be1d0f2f5e2b82fa85c8bf95655
    do_droid DroidSans.ttf             "Droid Sans"              da5b3c7758a2c8fbc4775beb69d7150493c7d312
    do_droid DroidSerif-BoldItalic.ttf "Droid Serif Bold Italic" c1602dc11bf0f7131aec21c7c3888195ad78e486
    do_droid DroidSerif-Bold.ttf       "Droid Serif Bold"        d7896b9c0723299553e95a00d27cbe52f7515c8c
    do_droid DroidSerif-Italic.ttf     "Droid Serif Italic"      117941be102c8f38a86a70ebccaecb8078f7027e
    do_droid DroidSerif-Regular.ttf    "Droid Serif"             7f243858e496ed1bb1faca9f3a7bbe52defcbb5d
}

#----------------------------------------------------------------

w_metadata eufonts fonts \
   title="Updated fonts for Romanian and Bulgarian" \
   publisher="Microsoft" \
   year="2008" \
   media="download" \
   file1="EUupdate.EXE" \
   installed_file1="$W_FONTSDIR_WIN/trebucbd.ttf"

load_eufonts()
{
    # https://www.microsoft.com/downloads/details.aspx?FamilyID=0ec6f335-c3de-44c5-a13d-a1e7cea5ddea&displaylang=en
    w_download eufonts http://download.microsoft.com/download/a/1/8/a180e21e-9c2b-4b54-9c32-bf7fd7429970/EUupdate.EXE 9b076c40cb63aa0d8512aa8e610ba11d3466e441
    w_try_cabextract -q --directory="$W_TMP" "$W_CACHE"/eufonts/EUupdate.EXE
    w_try cp -f "$W_TMP"/*.ttf "$W_FONTSDIR_UNIX"

    w_register_font ArialBI.ttf "Arial Bold Italic"
    w_register_font ArialI.ttf "Arial Italic"
    w_register_font Arial.ttf "Arial"
    w_register_font TimesBd.ttf "Times New Roman Bold"
    w_register_font TimesBI.ttf "Times New Roman Bold Italic"
    w_register_font TimesI.ttf "Times New Roman Italic"
    w_register_font Times.ttf "Times New Roman"
    w_register_font trebucbd.ttf "Trebuchet Bold"
    w_register_font trebucbi.ttf "Trebuchet Bold Italic"
    w_register_font trebucit.ttf "Trebuchet Italic"
    w_register_font trebuc.ttf "Trebuchet"
    w_register_font Verdanab.ttf "Verdana Bold"
    w_register_font Verdanai.ttf "Verdana Italian"
    w_register_font Verdana.ttf "Verdana"
    w_register_font Verdanaz.ttf "Verdana Bold Italic"
}

#----------------------------------------------------------------

w_metadata fakechinese fonts \
   title="Creates aliases for Chinese fonts using WenQuanYi fonts" \
   publisher="wenq.org" \
   year="2009"

load_fakechinese()
{
    w_call wenquanyi
    # Loads Wenquanyi fonts and sets aliases for Microsoft Chinese fonts
    # Aliases to set:
    # Microsoft JhengHei --> WenQuanYi Micro Hei
    # Microsoft YaHei --> WenQuanYi Micro Hei
    # SimHei --> WenQuanYi Micro Hei

    w_register_font_substitution "Microsoft JhengHei" "WenQuanYi Micro Hei"
    w_register_font_substitution "Microsoft YaHei" "WenQuanYi Micro Hei"
    w_register_font_substitution "SimHei" "WenQuanYi Micro Hei"
}

#----------------------------------------------------------------

w_metadata fakejapanese fonts \
   title="Creates aliases for Japanese fonts using Takao fonts" \
   publisher="Jun Kobayashi" \
   year="2010"

load_fakejapanese()
{
    w_call takao
    # Loads Takao fonts and sets aliases for MS Gothic and MS PGothic, mainly for Japanese language support
    # Aliases to set:
    # MS Gothic --> TakaoGothic
    # MS PGothic --> TakaoPGothic
    # MS Mincho --> TakaoMincho
    # MS PMincho --> TakaoPMincho
    # These aliases were taken from what was listed in Ubuntu's fontconfig definitions.

    w_register_font_substitution "MS Gothic" "TakaoGothic"
    w_register_font_substitution "MS PGothic" "TakaoPGothic"
    w_register_font_substitution "MS Mincho" "TakaoMincho"
    w_register_font_substitution "MS PMincho" "TakaoPMincho"
}

#----------------------------------------------------------------

w_metadata fakekorean fonts \
   title="Creates aliases for Korean fonts using Baekmuk fonts" \
   publisher="Wooderart Inc. / kldp.net" \
   year="1999"

load_fakekorean()
{
    w_call baekmuk
    # Loads Baekmuk fonts and sets as an alias for Gulim, Dotum, and Batang for Korean language support
    # Aliases to set:
    # Gulim --> Baekmuk Gulim
    # GulimChe --> Baekmuk Gulim
    # Batang --> Baekmuk Batang
    # BatangChe --> Baekmuk Batang
    # Dotum --> Baekmuk Dotum
    # DotumChe --> Baekmuk Dotum

    w_register_font_substitution "Gulim" "Baekmuk Gulim"
    w_register_font_substitution "GulimChe" "Baekmuk Gulim"
    w_register_font_substitution "Batang" "Baekmuk Batang"
    w_register_font_substitution "BatangChe" "Baekmuk Batang"
    w_register_font_substitution "Dotum" "Baekmuk Dotum"
    w_register_font_substitution "DotumChe" "Baekmuk Dotum"
}

#----------------------------------------------------------------

w_metadata fontfix fonts \
   title="Updated Arphic fonts" \
   publisher="Arphic" \
   year="2007" \
   media="download" \
   file1="ttf-arphic-ukai_0.1.20060108.orig.tar.gz" \
   installed_file1="$W_FONTSDIR_WIN/ukai.ttf"

load_fontfix()
{
    # some versions of ukai.ttf and uming.ttf crash .net and picasa
    # See http://bugs.winehq.org/show_bug.cgi?id=7098#c9
    # Could fix globally, but that needs root, so just fix for wine
    if test -f /usr/share/fonts/truetype/arphic/ukai.ttf
    then
        gotsum=`$SHA1SUM < /usr/share/fonts/truetype/arphic/ukai.ttf | sed 's/ .*//'`
        # FIXME: do all affected versions of the font have same sha1sum as Gutsy?  Seems unlikely.
        if [ "$gotsum"x = "96e1121f89953e5169d3e2e7811569148f573985"x ]
        then
            w_download fontfix https://launchpadlibrarian.net/1499628/ttf-arphic-ukai_0.1.20060108.orig.tar.gz 92e577602d71454a108968e79ab667451f3602a2
            gunzip -dc "$W_CACHE/fontfix/ttf-arphic-ukai_0.1.20060108.orig.tar.gz" | (cd "$W_TMP"; tar -xf -)
            w_try mv "$W_TMP"/ttf-arphic-ukai-0.1.20060108/*.ttf "$W_FONTSDIR_UNIX"
        fi
    fi

    if test -f /usr/share/fonts/truetype/arphic/uming.ttf
    then
        gotsum=`$SHA1SUM < /usr/share/fonts/truetype/arphic/uming.ttf | sed 's/ .*//'`
        if [ "$gotsum"x = "2a4f4a69e343c21c24d044b2cb19fd4f0decc82c"x ]
        then
            w_download fontfix https://launchpadlibrarian.net/1564410/ttf-arphic-uming_0.1.20060108.orig.tar.gz 1439cdd731906e9e5311f320c2cb33262b24ef91
            gunzip -dc "$W_CACHE/fontfix/ttf-arphic-uming_0.1.20060108.orig.tar.gz" | (cd "$W_TMP"; tar -xf -)
            w_try mv "$W_TMP"/ttf-arphic-uming-0.1.20060108/*.ttf "$W_FONTSDIR_UNIX"
        fi
    fi

    # Focht says Samyak is bad news, and font substitution isn't a good workaround.
    # I've seen psdkwin7 setup crash because of this; the symptom was a messagebox saying
    # SDKSetup encountered an error: The type initializer for 'Microsoft.WizardFramework.WizardSettings' threw an exception
    # and WINEDEBUG=+relay,+seh shows an exception very quickly after
    # Call KERNEL32.CreateFileW(0c83b36c L"Z:\\USR\\SHARE\\FONTS\\TRUETYPE\\TTF-ORIYA-FONTS\\SAMYAK-ORIYA.TTF",80000000,00000001,00000000,00000003,00000080,00000000) ret=70d44091
    if xlsfonts 2>/dev/null | egrep -i "samyak|oriya"
    then
        w_die "Please uninstall the Samyak/Oriya font, e.g. 'sudo dpkg -r ttf-oriya-fonts', then log out and log in again.  That font causes strange crashes in .net programs."
    fi
}

#----------------------------------------------------------------

w_metadata liberation fonts \
   title="Red Hat Liberation fonts (Sans, Serif, Mono)" \
   publisher="Red Hat" \
   year="2008" \
   media="download" \
   file1="liberation-fonts-1.04.tar.gz" \
   installed_file1="$W_FONTSDIR_WIN/LiberationMono-BoldItalic.ttf"

load_liberation()
{
    # http://www.redhat.com/promo/fonts/
    case `uname -s` in
    SunOS|Solaris)
      echo "If you get 'ERROR: Certificate verification error for fedorahosted.org: unable to get local issuer certificate':"
      echo "Then you need to add Verisign root certificates to your local keystore."
      echo "OpenSolaris users, see: http://www.linuxtopia.org/online_books/opensolaris_2008/SYSADV1/html/swmgrpatchtasks-14.html"
      echo "Or edit winetricks's download function, and add '--no-check-certificate' to the command."
      ;;
    esac

    w_download liberation https://fedorahosted.org/releases/l/i/liberation-fonts/liberation-fonts-1.04.tar.gz 097882c92e3260742a3dc3bf033792120d8635a3
    cd "$W_TMP"
    gunzip -dc "$W_CACHE"/liberation/liberation-fonts-1.04.tar.gz | tar -xf -
    mv liberation-fonts-1.04/*.ttf "$W_FONTSDIR_UNIX"

    w_register_font LiberationMono-BoldItalic.ttf "LiberationMono-BoldItalic"
    w_register_font LiberationMono-Bold.ttf "LiberationMono-Bold"
    w_register_font LiberationMono-Italic.ttf "LiberationMono-Italic"
    w_register_font LiberationMono-Regular.ttf "LiberationMono-Regular"
    w_register_font LiberationSans-BoldItalic.ttf "LiberationSans-BoldItalic"
    w_register_font LiberationSans-Bold.ttf "LiberationSans-Bold"
    w_register_font LiberationSans-Italic.ttf "LiberationSans-Italic"
    w_register_font LiberationSans-Regular.ttf "LiberationSans-Regular"
    w_register_font LiberationSerif-BoldItalic.ttf "LiberationSerif-BoldItalic"
    w_register_font LiberationSerif-Bold.ttf "LiberationSerif-Bold"
    w_register_font LiberationSerif-Italic.ttf "LiberationSerif-Italic"
    w_register_font LiberationSerif-Regular.ttf "LiberationSerif-Regular"
}

#----------------------------------------------------------------

w_metadata lucida fonts \
   title="MS Lucida Console font" \
   publisher="Microsoft" \
   year="1998" \
   media="download" \
   file1="eurofixi.exe" \
   installed_file1="$W_FONTSDIR_WIN/lucon.ttf"

load_lucida()
{
    w_download lucida ftp://ftp.microsoft.com/bussys/winnt/winnt-public/fixes/usa/NT40TSE/hotfixes-postSP3/Euro-fix/eurofixi.exe 64c47ad92265f6f10b0fd909a703d4fd1b05b2d5
    w_try_cabextract -d "$W_FONTSDIR_UNIX" -L -F 'lucon.ttf' "$W_CACHE"/lucida/eurofixi.exe
    w_register_font lucon.ttf "Lucida Console"
}

#----------------------------------------------------------------

w_metadata opensymbol fonts \
   title="OpenSymbol fonts (replacement for Wingdings)" \
   publisher="OpenOffice.org" \
   year="2010" \
   media="download" \
   file1="ttf-opensymbol_3.2.1-11_all.deb" \
   installed_file1="$W_FONTSDIR_WIN/opens___.ttf"

load_opensymbol()
{
    # The OpenSymbol fonts are a replacement for the Windows Wingdings font from OpenOffice.org.
    # Need to w_download from Debian since I can't find a standalone download from OpenOffice
    # Note: The source download package on debian is for _all_ of OpenOffice, which is 266 MB.
    w_download opensymbol http://ftp.us.debian.org/debian/pool/main/o/openoffice.org/ttf-opensymbol_3.2.1-11_all.deb 51f79c66f7361fae49053d8456ff1e0973748fb8

    cd "$W_TMP"
    w_try ar x "$W_CACHE/opensymbol/ttf-opensymbol_3.2.1-11_all.deb" data.tar.bz2
    w_try tar jvxf data.tar.bz2 ./usr/share/fonts/truetype/openoffice/opens___.ttf
    w_try mv "$W_TMP/usr/share/fonts/truetype/openoffice/opens___.ttf" "$W_FONTSDIR_UNIX"
    w_register_font opens___.ttf "OpenSymbol"
}

#----------------------------------------------------------------

w_metadata tahoma fonts \
   title="MS Tahoma font (not part of corefonts)" \
   publisher="Microsoft" \
   year="2007" \
   media="download" \
   file1="tahoma32.exe" \
   installed_file1="$W_FONTSDIR_WIN/Tahoma.TTF"

load_tahoma()
{
    # The tahoma and tahomabd fonts are needed by e.g. Steam

    w_download tahoma http://download.microsoft.com/download/office97pro/fonts/1/w95/en-us/tahoma32.exe 888ce7b7ab5fd41f9802f3a65fd0622eb651a068
    w_try_cabextract --directory="$W_TMP" "$W_CACHE"/tahoma/tahoma32.exe
    w_try cp -f "$W_TMP"/Tahoma.TTF "$W_FONTSDIR_UNIX"/tahoma.ttf
    w_try cp -f "$W_TMP"/Tahomabd.TTF "$W_FONTSDIR_UNIX"/tahomabd.ttf

    # FIXME:  Wine seems to nuke the registry entries for Tahoma.  Why?  Font Xplorer always lists it as 'not installed'.
    w_register_font tahoma.ttf "Tahoma"
    w_register_font tahomabd.ttf "Tahoma Bold"

    # ? does some app assume it can overwrite these, or is this a leftover from before we had install checks?
    chmod +w "$W_FONTSDIR_UNIX"/tahoma*.ttf
}

#----------------------------------------------------------------

w_metadata takao fonts \
   title="Takao Japanese fonts" \
   publisher="Jun Kobayashi" \
   year="2010" \
   media="download" \
   file1="takao-fonts-ttf-003.02.01.zip" \
   installed_file1="$W_FONTSDIR_WIN/TakaoGothic.ttf"

load_takao()
{
    # The Takao font provides Japanese glyphs.  May also be needed with fakejapanese function above.
    # See http://launchpad.net/takao-fonts for project page
    w_download takao http://launchpad.net/takao-fonts/003.02/003.02.01/+download/takao-fonts-ttf-003.02.01.zip 4f636d5c7c1bc16b96ea723adb16838cfb6df059
    cp -f "$W_CACHE"/takao/takao-fonts-ttf-003.02.01.zip "$W_TMP"
    w_try_unzip -d "$W_TMP" "$W_TMP"/takao-fonts-ttf-003.02.01.zip
    w_try cp -f "$W_TMP"/takao-fonts-ttf-003.02.01/*.ttf "$W_FONTSDIR_UNIX"

    w_register_font TakaoGothic.ttf "TakaoGothic"
    w_register_font TakaoPGothic.ttf "TakaoPGothic"
    w_register_font TakaoMincho.ttf "TakaoMincho"
    w_register_font TakaoPMincho.ttf "TakaoPMincho"
    w_register_font TakaoExGothic.ttf "TakaoExGothic"
    w_register_font TakaoExMincho.ttf "TakaoExMincho"
}

#----------------------------------------------------------------

w_metadata uff fonts \
   title="Ubuntu Font Family" \
   publisher="Ubuntu" \
   year="2010" \
   media="download" \
   file1="ubuntu-font-family-0.70.1.zip" \
   installed_file1="$W_FONTSDIR_WIN/Ubuntu-R.ttf" \
   homepage="https://launchpad.net/ubuntu-font-family"

load_uff()
{
    w_download uff http://font.ubuntu.com/download/ubuntu-font-family-0.70.1.zip efbab0d5d8cb5cff091307d2360dcb1bfe1ae6e1
    cd "$W_TMP"
    w_try_unzip "$W_CACHE"/uff/ubuntu-font-family-0.70.1.zip
    mv ubuntu-font-family-0.70.1/*.ttf "$W_FONTSDIR_UNIX"

    w_register_font Ubuntu-R.ttf "Ubuntu"
    w_register_font Ubuntu-I.ttf "Ubuntu Italic"
    w_register_font Ubuntu-B.ttf "Ubuntu Bold"
    w_register_font Ubuntu-BI.ttf "Ubuntu Bold Italic"
}

#----------------------------------------------------------------

w_metadata wenquanyi fonts \
   title="WenQuanYi CJK font" \
   publisher="wenq.org" \
   year="2009" \
   media="download" \
   file1="wqy-microhei-0.2.0-beta.tar.gz" \
   installed_file1="$W_FONTSDIR_WIN/wqy-microhei.ttc"

load_wenquanyi()
{
    # See http://wenq.org/enindex.cgi
    # Donate at http://wenq.org/enindex.cgi?Download(en)#MicroHei_Beta if you want to help support free CJK font development
    w_download wenquanyi $WINETRICKS_SOURCEFORGE/wqy/wqy-microhei-0.2.0-beta.tar.gz 28023041b22b6368bcfae076de68109b81e77976
    cd "$W_TMP/"
    gunzip -dc "$W_CACHE/wenquanyi/wqy-microhei-0.2.0-beta.tar.gz" | tar -xf -
    w_try mv wqy-microhei/wqy-microhei.ttc "$W_FONTSDIR_UNIX"
    w_register_font wqy-microhei.ttc "WenQuanYi Micro Hei"
}

#----------------------------------------------------------------

w_metadata unifont fonts \
   title="Unifont alternative to Arial Unicode MS" \
   publisher="Roman Czyborra / GNU" \
   year="2008" \
   media="download" \
   file1="unifont-5.1.20080907.zip" \
   installed_file1="$W_FONTSDIR_WIN/unifont.ttf"

load_unifont()
{
    # The GNU Unifont provides glyphs for just about everything in common language.  It is intended for multilingual usage.
    # See http://unifoundry.com/unifont.html for project page
    w_download unifont http://unifoundry.com/unifont-5.1.20080907.zip bb8a3960dc0a96aa305de28312ea8a0ab64123d2
    cp -f "$W_CACHE"/unifont/unifont-5.1.20080907.zip "$W_TMP"
    w_try_unzip -d "$W_TMP" "$W_TMP"/unifont-5.1.20080907.zip
    w_try cp -f "$W_TMP"/unifont-5.1.20080907.ttf "$W_FONTSDIR_UNIX/unifont.ttf"

    w_register_font unifont.ttf "Unifont"
    w_register_font_substitution "Arial Unicode MS" "Unifont"
}

#----------------------------------------------------------------

w_metadata allfonts fonts \
   title="All fonts" \
   publisher="various" \
   year="1998-2010" \
   media="download" 

load_allfonts()
{
    # This verb uses reflection, should probably do it portably instead, but that would require keeping it up to date
    for file in "$WINETRICKS_METADATA"/fonts/*.vars
    do
        cmd=`basename $file .vars`
        case $cmd in
        allfonts|cjkfonts) ;;
        *) w_call $cmd;;
        esac
    done
}

#----------------------------------------------------------------
# Apps
#----------------------------------------------------------------

w_metadata 7zip apps \
   title="7-Zip" \
   publisher="Igor Pavolv" \
   year="1999" \
   media="download" \
   file1="7z465.exe" \
   installed_exe1="$W_PROGRAMS_X86_WIN/7-Zip/7z.exe"

load_7zip()
{
    # FIXME: use more up to date version
    w_download 7zip http://downloads.sourceforge.net/sevenzip/7z465.exe c36012e960fa3932cd23f30ac5b0fe722740243a
    cd "$W_CACHE"/7zip
    w_try $WINE 7z465.exe $W_UNATTENDED_SLASH_S
    w_declare_exe "$W_PROGRAMS_X86_WIN\\7-Zip" "7z.exe %1 %2 %3 %4 %5"
}

#----------------------------------------------------------------

w_metadata  abiword apps \
   title="AbiWord 2.8.6" \
   publisher="AbiSource" \
   year="2010" \
   media="download" \
   file1="abiword-setup-2.8.6.exe" \
   installed_exe1="$W_PROGRAMS_X86_WIN/AbiWord/bin/AbiWord.exe"

load_abiword()
{
    w_download abiword http://www.abisource.com/downloads/abiword/2.8.6/Windows/abiword-setup-2.8.6.exe a91acd3f60e842d23556032d34f1600602768318
    cd "$W_CACHE"/abiword
    w_try $WINE abiword-setup-2.8.6.exe $W_UNATTENDED_SLASH_S
    w_declare_exe "$W_PROGRAMS_X86_WIN\\AbiWord\\bin" AbiWord.exe
}

#----------------------------------------------------------------

w_metadata autohotkey apps \
   title="Autohotkey" \
   publisher="autohotkey.org" \
   year="2010" \
   media="download" \
   file1="AutoHotkey104805_Install.exe" \
   installed_exe1="$W_PROGRAMS_X86_WIN/AutoHotkey/AutoHotkey.exe"

load_autohotkey()
{
    w_download autohotkey http://www.autohotkey.net/programs/AutoHotkey104805_Install.exe 13e5a9ca6d5b7705f1cd02560c3af4d38b1904fc
    cd "$W_CACHE"/autohotkey
    w_try $WINE AutoHotkey104805_Install.exe $W_UNATTENDED_SLASH_S
}

#----------------------------------------------------------------

w_metadata cmake apps \
   title="CMake 2.8" \
   publisher="Kitware" \
   year="2010" \
   media="download" \
   file1="cmake-2.8.2-win32-x86.exe" \
   installed_exe1="$W_PROGRAMS_X86_WIN/CMake 2.8/bin/cmake-gui.exe"

load_cmake()
{
    w_download cmake http://www.cmake.org/files/v2.8/cmake-2.8.2-win32-x86.exe 2c46f4e804787b231c2f45e1b43f1838462e8dfe
    cd "$W_CACHE"/cmake
    w_try $WINE cmake-2.8.2-win32-x86.exe $W_UNATTENDED_SLASH_S

    w_declare_exe "$W_PROGRAMS_X86_WIN\\CMake 2.8\\bin" "cmake-gui.exe"
}

#----------------------------------------------------------------

w_metadata colorprofile apps \
   title="Standard RGB color profile" \
   publisher="Microsoft" \
   year="2005" \
   media="download" \
   file1="ColorProfile.exe" \
   installed_exe1="$W_DRIVE_C/windows/system32/spool/drivers/color/sRGB Color Space Profile.icm"

load_colorprofile()
{
    w_download colorprofile http://download.microsoft.com/download/whistler/hwdev1/1.0/wxp/en-us/ColorProfile.exe 6b72836b32b343c82d0760dff5cb51c2f47170eb
    w_try_unzip -d "$W_TMP" "$W_CACHE"/colorprofile/ColorProfile.exe

    # It's in system32 for both win32/win64
    mkdir -p "$W_WINDIR_UNIX"/system32/spool/drivers/color
    w_try cp -f "$W_TMP/sRGB Color Space Profile.icm" "$W_WINDIR_UNIX"/system32/spool/drivers/color
}

#----------------------------------------------------------------

w_metadata controlpad apps \
   title="MS ActiveX Control Pad" \
   publisher="Microsoft" \
   year="1997" \
   media="download" \
   file1="setuppad.exe" \
   installed_exe1="$W_PROGRAMS_X86_WIN/ActiveX Control Pad/PED.EXE"

load_controlpad()
{
    # http://msdn.microsoft.com/en-us/library/ms968493.aspx
    w_call wsh57
    w_download controlpad http://download.microsoft.com/download/activexcontrolpad/install/4.0.0.950/win98mexp/en-us/setuppad.exe 8921e0f52507ca6a373c94d222777c750fb48af7
    w_try_cabextract --directory="$W_TMP" "$W_CACHE"/controlpad/setuppad.exe

    echo "If setup says 'Unable to start DDE ...', press Ignore"

    cd "$W_TMP"
    case "$W_UNATTENDED_SLASH_Q" in
    "") quiet="" ;;
    *)  quiet="/qt"
    esac
    w_try $WINE setup $quiet

    if ! test -f "$W_SYSTEM32_DLLS"/FM20.DLL
    then
        w_die "Install failed.  Please report,  If you just wanted fm20.dll, try installing art2min instead."
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\ActiveX Control Pad" "PED.EXE"
}

#----------------------------------------------------------------

w_metadata cygwin apps \
   title="cygwin" \
   publisher="Red Hat" \
   year="2009" \
   media="download" \
   file1="setup.exe" \
   installed_exe1="C:/cygwin/bin/sh.exe"

load_cygwin()
{
    if w_workaround_wine_bug 21206
    then
        # Wine can't handle current cygwin, so use some random verison of cygwin's setup from mid-2009
        w_download cygwin http://kegel.com/cygwin/1.5/setup.exe 5cfb8ebe4f385b0fcffa04d22d607ec75ea05180
        w_warn "Paste in ftp://www.fruitbat.org/pub/cygwin/circa/2009/09/08/111037 as the repo url for now, until bug 21206 is fixed"
        # -X option is insecure, but we have to use it because fruitbat.org didn't archive .sig files :-(
        _W_cygopts="-X"
    else
        w_download cygwin http://cygwin.com/setup.exe aaa2552de78e14891937c1fde86032e811cf3c3a
        _W_cygopts=
    fi

    mkdir -p "$W_DRIVE_C"/cygpkgs
    # If you happen to have saved your cygpkgs directory, unpack it now
    test -f "$W_CACHE/cygwin/cygpkgs.tgz" && (cd "$W_DRIVE_C"; gunzip -dc "$W_CACHE/cygwin/cygpkgs.tgz" | tar -xf -)
    # FIXME: automate the base installation
    cp "$W_CACHE/cygwin/setup.exe" "$W_DRIVE_C"/cygpkgs
    cd "$W_DRIVE_C"/cygpkgs
    w_try $WINE setup.exe $_W_cygopts
    unset _W_cygopts
}

#----------------------------------------------------------------

w_metadata dxdiag apps \
   title="DirectX Diagnostic Tool" \
   publisher="Microsoft" \
   year="2010" \
   media="download" \
   file1="../directx9/directx_feb2010_redist.exe" \
   installed_file1="$W_SYSTEM32_DLLS_WIN/dxdiag.exe"

load_dxdiag()
{
    helper_directx_dl

    w_try_cabextract -d "$W_TMP" -L -F dxnt.cab "$W_CACHE"/directx9/$DIRECTX_NAME
    w_try_cabextract -d "$W_SYSTEM32_DLLS" -L -F dxdiag.exe "$W_TMP/dxnt.cab"
    w_override_dlls native dxdiag.exe

    if w_workaround_wine_bug 1429
    then
        w_call dxdiagn
    fi
    if w_workaround_wine_bug 25715
    then
        w_call quartz
    fi
    if w_workaround_wine_bug 25716
    then
        w_call devenum
    fi
}

#----------------------------------------------------------------

w_metadata firefox apps \
   title="Firefox 3.6.13" \
   publisher="Mozilla" \
   year="2010" \
   media="download" \
   file1="Firefox Setup 3.6.13.exe" \
   installed_exe1="$W_PROGRAMS_X86_WIN/Mozilla Firefox/firefox.exe"

load_firefox()
{
    w_download firefox "http://releases.mozilla.org//pub/mozilla.org/firefox/releases/3.6.13/win32/en-US/Firefox%20Setup%203.6.13.exe" ac9a021dc07c9a269b547b2a5b07719f61cd9368 "Firefox Setup 3.6.13.exe"
    cd "$W_CACHE"/firefox
    if test $W_OPT_UNATTENDED = 1
    then
       w_try $WINE "Firefox Setup 3.6.13.exe" -ms
    else
       w_try $WINE "Firefox Setup 3.6.13.exe"
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Mozilla Firefox" firefox.exe
}

#----------------------------------------------------------------

w_metadata firefox4 apps \
   title="Firefox 4.0 Beta 9" \
   publisher="Mozilla" \
   year="2011" \
   media="download" \
   file1="Firefox Setup 4.0 Beta 9.exe" \
   installed_exe1="$W_PROGRAMS_X86_WIN/Mozilla Firefox 4.0 Beta 9/firefox.exe"

load_firefox4()
{
    if w_workaround_wine_bug 22972 # fixed in wine-1.3.0
    then
        w_warn "Requires wine-1.3.0 or later to install"
    fi

    w_download firefox4 "http://mozilla-mirror.naist.jp//firefox/releases/4.0b9/win32/en-US/Firefox%20Setup%204.0%20Beta%209.exe" a80780d52aa8e1a8e5d9c9ffd4238441cb7d1a52 "Firefox Setup 4.0 Beta 9.exe"
    cd "$W_CACHE"/firefox4
    if test $W_OPT_UNATTENDED = 1
    then
       w_try $WINE "Firefox Setup 4.0 Beta 9.exe" -ms
    else
       w_try $WINE "Firefox Setup 4.0 Beta 9.exe"
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Mozilla Firefox 4.0 Beta 9" firefox.exe
}

#----------------------------------------------------------------

w_metadata fontxplorer apps \
   title="Font Xplorer 1.2.2" \
   publisher="Moon Software" \
   year="2001" \
   media="download" \
   file1="Font_Xplorer_122_Free.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/Font Xplorer/FXplorer.exe" \
   homepage="http://www.moonsoftware.com/fxplorer.asp"

load_fontxplorer()
{
    w_download fontxplorer "http://www.moonsoftware.com/getfile.asp?fxfull" 22feb63be28730cbfad5458b139464490a25a68d Font_Xplorer_122_Free.exe

    cd "$W_CACHE/fontxplorer"
    w_try $WINE Font_Xplorer_122_Free.exe $W_UNATTENDED_SLASH_S
    w_declare_exe "$W_PROGRAMS_X86_WIN\\Font Xplorer" "FXplorer.exe"
}

#----------------------------------------------------------------

w_metadata ie6 apps \
   title="Internet Explorer 6" \
   publisher="Microsoft" \
   year="2002" \
   media="download" \
   file1="ie60.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/Internet Explorer/iedetect.dll"

load_ie6()
{
    # Installer doesn't support Win64, and I can't find a x64 version on microsoft.com
    if [ $W_ARCH = win64 ]
    then
        w_die "This package does not work on a 64-bit installation"
    fi

    w_download ie6 http://browsers-us.mirrors.zensoft.net/ie/win32/6.0/ie60.exe 8e483db28ff01a7cabd39147ab6c59753ea1f533

    cd "$W_TMP"
    $WINE "$W_CACHE"/ie6/ie60.exe

    w_call msls31

    # Unregister Wine IE
    if [ ! -f "$W_SYSTEM32_DLLS"/plugin.ocx ]
    then
        w_try $WINE iexplore -unregserver
    fi

    # Change the override to the native so we are sure we use and register them
    w_override_dlls native,builtin iexplore.exe itircl itss jscript mlang mshtml msimtf shdoclc shdocvw shlwapi urlmon

    # Remove the fake dlls, if any
    mv "$W_PROGRAMS_UNIX"/"Internet Explorer"/iexplore.exe "$W_PROGRAMS_UNIX"/"Internet Explorer"/iexplore.exe.bak
    for dll in itircl itss jscript mlang mshtml msimtf shdoclc shdocvw shlwapi urlmon
    do
        test -f "$W_SYSTEM32_DLLS"/$dll.dll &&
        mv "$W_SYSTEM32_DLLS"/$dll.dll "$W_SYSTEM32_DLLS"/$dll.dll.bak
    done

    # The installer doesn't want to install iexplore.exe in XP mode.
    w_set_winver win2k

    # Workaround http://bugs.winehq.org/show_bug.cgi?id=21009
    # See also http://code.google.com/p/winezeug/issues/detail?id=78
    rm -f "$W_SYSTEM32_DLLS"/browseui.dll "$W_SYSTEM32_DLLS"/inseng.dll

    # Work around http://bugs.winehq.org/show_bug.cgi?id=25432
    w_try_cabextract -F inseng.dll "$W_TMP/IE 6.0 Full/ACTSETUP.CAB"
    mv inseng.dll "$W_SYSTEM32_DLLS"
    w_override_dlls native inseng.dll

    cd "$W_TMP/IE 6.0 Full"
    if [ $W_UNATTENDED_SLASH_Q ]
    then
        $WINE IE6SETUP.EXE /q:a /r:n /c:"ie6wzd /S:""#e"" /q:a /r:n"
    else
        $WINE IE6SETUP.EXE
    fi

    # IE6 exits with 194 to signal a reboot
    status=$?
    case $status in
    0|194) ;;
    *) w_die ie6 installation failed
    esac

    # Work around DLL registration bug until ierunonce/RunOnce/wineboot is fixed
    # FIXME: whittle down this list
    cd "$W_SYSTEM32_DLLS"
    for i in actxprxy.dll browseui.dll browsewm.dll cdfview.dll ddraw.dll \
      dispex.dll dsound.dll iedkcs32.dll iepeers.dll iesetup.dll \
      imgutil.dll inetcomm.dll inseng.dll isetup.dll jscript.dll laprxy.dll \
      mlang.dll mshtml.dll mshtmled.dll msi.dll msident.dll \
      msoeacct.dll msrating.dll mstime.dll msxml3.dll occache.dll \
      ole32.dll oleaut32.dll olepro32.dll pngfilt.dll quartz.dll \
      rpcrt4.dll rsabase.dll rsaenh.dll scrobj.dll scrrun.dll \
      shdocvw.dll shell32.dll urlmon.dll vbscript.dll webcheck.dll \
      wshcon.dll wshext.dll asctrls.ocx hhctrl.ocx mscomct2.ocx \
      plugin.ocx proctexe.ocx tdc.ocx webcheck.dll wshom.ocx
    do
        $WINE regsvr32 /i $i > /dev/null 2>&1
    done

    # Set windows version back to user's default. Leave at win2k for better rendering (is there a bug for that?)
    w_unset_winver

    # the ie6 we use these days lacks pngfilt, so grab that
    w_call pngfilt
}

#----------------------------------------------------------------

w_metadata ie7 apps \
   title="Internet Explorer 7" \
   publisher="Microsoft" \
   year="2008" \
   media="download" \
   file1="IE7-WindowsXP-x86-enu.exe" \
   installed_file1="c:/windows/ie7.log"

load_ie7()
{
    # Unregister Wine IE
    if grep -q -i "wine placeholder" "$W_PROGRAMS_X86_UNIX/Internet Explorer/iexplore.exe"
    then 
        w_try $WINE iexplore -unregserver
    fi
    
    # Change the override to the native so we are sure we use and register them
    w_override_dlls native,builtin iexplore.exe itircl itss jscript mshtml msimtf shdoclc shdocvw shlwapi urlmon xmllite

    # Bundled updspapi cannot work on wine
    w_override_dlls builtin updspapi

    # Remove the fake dlls from the existing WINEPREFIX
    for dll in itircl itss jscript mshtml msimtf shdoclc shdocvw shlwapi urlmon
    do
        test -f "$W_SYSTEM32_DLLS"/$dll.dll &&
        mv "$W_SYSTEM32_DLLS"/$dll.dll "$W_SYSTEM32_DLLS"/$dll.dll.bak
    done

    # See http://bugs.winehq.org/show_bug.cgi?id=16013
    # Find instructions to create this file in dlls/wintrust/tests/crypt.c
    w_download ie7 http://winezeug.googlecode.com/svn/trunk/winetricks_files/winetest.cat ac8f50dd54d011f3bb1dd79240dae9378748449f

    # Put a dummy catalog file in place
    mkdir -p "$W_SYSTEM32_DLLS"/catroot/\{f750e6c3-38ee-11d1-85e5-00c04fc295ee\}
    w_try cp -f "$W_CACHE"/ie7/winetest.cat "$W_SYSTEM32_DLLS"/catroot/\{f750e6c3-38ee-11d1-85e5-00c04fc295ee\}/oem0.cat

    # Install
    w_download ie7 http://download.microsoft.com/download/3/8/8/38889DC1-848C-4BF2-8335-86C573AD86D9/IE7-WindowsXP-x86-enu.exe d39b89c360fbaa9706b5181ae4718100687a5326
    if test "$W_UNATTENDED_SLASH_Q" = ""
    then
        quiet=""
    else
        quiet="/quiet"
    fi
    cd "$W_CACHE"/ie7
    
    # KLUDGE: if / is writable, having a z: mapping to it causes ie7 to put temporary directories on Z:\
    # so hide it temporarily.  This is not very robust!
    rm -f "$WINEPREFIX/dosdevices/z:.bak_wt"
    mv "$WINEPREFIX/dosdevices/z:" "$WINEPREFIX/dosdevices/z:.bak_wt"

    # FIXME: can't check status, as it always reports failure on wine?
    if w_workaround_wine_bug 21947
    then
        WINEDEBUG=warn+heap $WINE IE7-WindowsXP-x86-enu.exe $quiet
    else
        $WINE IE7-WindowsXP-x86-enu.exe $quiet
    fi

    # END KLUDGE: restore z:, assuming user didn't kill us
    mv "$WINEPREFIX/dosdevices/z:.bak_wt" "$WINEPREFIX/dosdevices/z:"

    # Work around DLL registration bug until ierunonce/RunOnce/wineboot is fixed
    # FIXME: whittle down this list
    cd "$W_SYSTEM32_DLLS"
    for i in actxprxy.dll browseui.dll browsewm.dll cdfview.dll ddraw.dll \
      dispex.dll dsound.dll iedkcs32.dll iepeers.dll iesetup.dll \
      imgutil.dll inetcomm.dll inseng.dll isetup.dll jscript.dll laprxy.dll \
      mlang.dll mshtml.dll mshtmled.dll msi.dll msident.dll \
      msoeacct.dll msrating.dll mstime.dll msxml3.dll occache.dll \
      ole32.dll oleaut32.dll olepro32.dll pngfilt.dll quartz.dll \
      rpcrt4.dll rsabase.dll rsaenh.dll scrobj.dll scrrun.dll \
      shdocvw.dll shell32.dll urlmon.dll vbscript.dll webcheck.dll \
      wshcon.dll wshext.dll asctrls.ocx hhctrl.ocx mscomct2.ocx \
      plugin.ocx proctexe.ocx tdc.ocx webcheck.dll wshom.ocx
    do
        $WINE regsvr32 /i $i > /dev/null 2>&1
    done

    # Seeing is believing
    case $WINETRICKS_GUI in
    none)
        w_warn "To start ie7, use the command $WINE '${W_PROGRAMS_WIN}\\\\Internet Explorer\\\\iexplore'"
        ;;
    *)
        w_warn "Starting ie7.  To start it later, use the command $WINE '${W_PROGRAMS_WIN}\\\\Internet Explorer\\\\iexplore'"
        $WINE "${W_PROGRAMS_WIN}\\Internet Explorer\\iexplore" http://www.microsoft.com/windows/internet-explorer/ie7/ > /dev/null 2>&1 &
        ;;
    esac
}

#----------------------------------------------------------------

w_metadata ie8 apps \
   title="Internet Explorer 8 (broken)" \
   publisher="Microsoft" \
   year="2009" \
   media="download" \
   file1="IE8-WindowsXP-x86-ENU.exe" \
   installed_file1="c:/windows/ie8.log"

load_ie8()
{
    # Unregister Wine IE
    if grep -q -i "wine placeholder" "$W_PROGRAMS_X86_UNIX/Internet Explorer/iexplore.exe"
    #if [ ! -f "$W_SYSTEM32_DLLS"/plugin.ocx ]
    then 
        w_try $WINE iexplore -unregserver
    fi

    w_call msls31
    
    # Change the override to the native so we are sure we use and register them
    w_override_dlls native,builtin iexplore.exe itircl itss jscript msctf mshtml shdoclc shdocvw shlwapi urlmon xmllite

    # Bundled updspapi cannot work on wine
    w_override_dlls builtin updspapi
    
    # Remove the fake dlls from the existing WINEPREFIX
    for dll in browseui.dll inseng.dll itircl itss jscript msctf mshtml  shdoclc shdocvw shlwapi urlmon
    do
        test -f "$W_SYSTEM32_DLLS"/$dll.dll &&
        mv "$W_SYSTEM32_DLLS"/$dll.dll "$W_SYSTEM32_DLLS"/$dll.dll.bak
    done

    # See http://bugs.winehq.org/show_bug.cgi?id=16013
    # Find instructions to create this file in dlls/wintrust/tests/crypt.c
    w_download ie8 http://winezeug.googlecode.com/svn/trunk/winetricks_files/winetest.cat ac8f50dd54d011f3bb1dd79240dae9378748449f

    # Put a dummy catalog file in place
    mkdir -p "$W_SYSTEM32_DLLS"/catroot/\{f750e6c3-38ee-11d1-85e5-00c04fc295ee\}
    w_try cp -f "$W_CACHE"/ie8/winetest.cat "$W_SYSTEM32_DLLS"/catroot/\{f750e6c3-38ee-11d1-85e5-00c04fc295ee\}/oem0.cat

    w_download ie8 http://download.microsoft.com/download/C/C/0/CC0BD555-33DD-411E-936B-73AC6F95AE11/IE8-WindowsXP-x86-ENU.exe e489483e5001f95da04e1ebf3c664173baef3e26 
    if [ $W_UNATTENDED_SLASH_Q ]
    then
        quiet="/quiet /forcerestart"
    else
        quiet=""
    fi
    cd "$W_CACHE"/ie8

    # KLUDGE: if / is writable, having a z: mapping to it causes ie8 to put temporary directories on Z:\
    # so hide it temporarily.  This is not very robust!
    rm -f "$WINEPREFIX/dosdevices/z:.bak_wt"
    mv "$WINEPREFIX/dosdevices/z:" "$WINEPREFIX/dosdevices/z:.bak_wt"

    # FIXME: There's an option for /updates-noupdates to disable checking for updates, but that 
    # forces the install to fail on Wine. Not sure if it's an IE8 or Wine bug...
    # FIXME: can't check status, as it always reports failure on wine?
    $WINE IE8-WindowsXP-x86-ENU.exe $quiet
    # END KLUDGE: restore z:, assuming user didn't kill us
    mv "$WINEPREFIX/dosdevices/z:.bak_wt" "$WINEPREFIX/dosdevices/z:"

    # Work around DLL registration bug until ierunonce/RunOnce/wineboot is fixed
    # FIXME: whittle down this list
    cd "$W_SYSTEM32_DLLS"
    for i in actxprxy.dll browseui.dll browsewm.dll cdfview.dll ddraw.dll \
      dispex.dll dsound.dll iedkcs32.dll iepeers.dll iesetup.dll \
      imgutil.dll inetcomm.dll isetup.dll jscript.dll laprxy.dll \
      mlang.dll msctf.dll mshtml.dll mshtmled.dll msi.dll msimtf.dll msident.dll \
      msoeacct.dll msrating.dll mstime.dll msxml3.dll occache.dll \
      ole32.dll oleaut32.dll olepro32.dll pngfilt.dll quartz.dll \
      rpcrt4.dll rsabase.dll rsaenh.dll scrobj.dll scrrun.dll \
      shdocvw.dll shell32.dll urlmon.dll vbscript.dll webcheck.dll \
      wshcon.dll wshext.dll asctrls.ocx hhctrl.ocx mscomct2.ocx \
      plugin.ocx proctexe.ocx tdc.ocx uxtheme.dll webcheck.dll wshom.ocx
    do
        $WINE regsvr32 /i $i > /dev/null 2>&1
    done

    # FIXME: According to http://www.wine-reviews.net/wine-reviews/microsoft/internet-explorer-8-on-linux-with-wine.html
    # may also need native msctf, msimtf, and uxtheme.  Is this why the UI doesn't work yet?
}

#----------------------------------------------------------------

# This whole verb is a workaround for http://bugs.winehq.org/show_bug.cgi?id=25648
# and http://bugs.winehq.org/show_bug.cgi?id=19313
w_metadata ie68 apps \
   title="IE8 with IE6-ish gui.  (Kludge until wine can run ie8 gui.)" \
   publisher="Microsoft" \
   year="2009" \
   media="download" \
   file1="IE8-WindowsXP-x86-enu.exe" \
   installed_exe1="$W_PROGRAMS_X86_WIN/Internet Explorer/iexplore.exe"

load_ie68()
{
    # There's probably an easier way to get fake iexplore menus to work with ie8's guts,
    # but installing ie6 before installing ie8 does the trick for now.
    w_call ie6
    sleep 10
    w_call ie8

    # Set the home page to a search engine so you can at least navigate by searching
    cat > "$W_TMP"/homepage.reg <<_EOF_
REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main]
"Start Page"="http://google.com/"
_EOF_
    w_try_regedit "$W_TMP_WIN"\\homepage.reg

    # Seeing is believing
    case $WINETRICKS_GUI in
    none)
        w_warn "To start 'ie68', use the command '$WINE iexplore'"
        ;;
    *)
        w_warn "Starting 'ie68'.  To start it later, use the command '$WINE iexplore'"
        $WINE iexplore > /dev/null 2>&1 &
        ;;
    esac
}

#----------------------------------------------------------------

w_metadata mingw apps \
   title="Minimalist GNU for Windows, including GCC for Windows" \
   publisher="GNU" \
   year="2010-2011" \
   media="download" \
   file1="binutils-2.21-2-mingw32-bin.tar.lzma" \
   installed_exe1="c:/MinGW/bin/gcc.exe" \
   homepage="http://mingw.org/wiki/Getting_Started"

load_mingw()
{
    w_download mingw $WINETRICKS_SOURCEFORGE/mingw/files/binutils-2.21-2-mingw32-bin.tar.lzma
    w_download mingw $WINETRICKS_SOURCEFORGE/mingw/files/gcc-core-4.5.2-1-mingw32-bin.tar.lzma
    w_download mingw $WINETRICKS_SOURCEFORGE/mingw/files/libgcc-4.5.2-1-mingw32-dll-1.tar.lzma
    w_download mingw $WINETRICKS_SOURCEFORGE/mingw/files/libgmpxx-5.0.1-1-mingw32-dll-4.tar.lzma
    w_download mingw $WINETRICKS_SOURCEFORGE/mingw/files/libgmp-5.0.1-1-mingw32-dll-10.tar.lzma
    w_download mingw $WINETRICKS_SOURCEFORGE/mingw/files/libmpc-0.8.1-1-mingw32-dll-2.tar.lzma
    w_download mingw $WINETRICKS_SOURCEFORGE/mingw/files/libiconv-1.13.1-1-mingw32-dll-2.tar.lzma
    w_download mingw $WINETRICKS_SOURCEFORGE/mingw/files/mingwrt-3.18-mingw32-dev.tar.gz
    w_download mingw $WINETRICKS_SOURCEFORGE/mingw/files/mingwrt-3.18-mingw32-dll.tar.gz
    w_download mingw $WINETRICKS_SOURCEFORGE/mingw/files/libmpfr-2.4.1-1-mingw32-dll-1.tar.lzma
    w_download mingw $WINETRICKS_SOURCEFORGE/mingw/files/libpthread-2.8.0-3-mingw32-dll-2.tar.lzma
    w_download mingw $WINETRICKS_SOURCEFORGE/mingw/files/w32api-3.15-1-mingw32-dev.tar.lzma

    mkdir "$W_DRIVE_C"/MinGW
    cd "$W_DRIVE_C"/MinGW
    lzma -d -c "$W_CACHE"/mingw/binutils-2.21-2-mingw32-bin.tar.lzma | tar xf -
    gzip -d -c "$W_CACHE"/mingw/mingwrt-3.18-mingw32-dev.tar.gz | tar xf -
    gzip -d -c "$W_CACHE"/mingw/mingwrt-3.18-mingw32-dll.tar.gz | tar xf -
    lzma -d -c "$W_CACHE"/mingw/w32api-3.15-1-mingw32-dev.tar.lzma | tar xf -
    lzma -d -c "$W_CACHE"/mingw/libgmp-5.0.1-1-mingw32-dll-10.tar.lzma | tar xf -
    lzma -d -c "$W_CACHE"/mingw/libmpc-0.8.1-1-mingw32-dll-2.tar.lzma | tar xf -
    lzma -d -c "$W_CACHE"/mingw/libgmpxx-5.0.1-1-mingw32-dll-4.tar.lzma | tar xf -
    lzma -d -c "$W_CACHE"/mingw/libiconv-1.13.1-1-mingw32-dll-2.tar.lzma | tar xf -
    lzma -d -c "$W_CACHE"/mingw/libmpfr-2.4.1-1-mingw32-dll-1.tar.lzma | tar xf -
    lzma -d -c "$W_CACHE"/mingw/libpthread-2.8.0-3-mingw32-dll-2.tar.lzma | tar xf -
    lzma -d -c "$W_CACHE"/mingw/libgcc-4.5.2-1-mingw32-dll-1.tar.lzma | tar xf -
    lzma -d -c "$W_CACHE"/mingw/gcc-core-4.5.2-1-mingw32-bin.tar.lzma | tar xf -

    w_append_path 'C:\MinGW\bin'
}

#----------------------------------------------------------------

w_metadata mpc apps \
   title="Media Player Classic - Home Cinema" \
   publisher="doom9 folks" \
   year="2010" \
   media="download" \
   file1="MPC-HomeCinema.1.4.2499.0.x86.zip" \
   installed_file1="$W_PROGRAMS_X86_WIN/Media Player Classic/mpc-hc.exe" \
   homepage="http://mpc-hc.sourceforge.net"

load_mpc()
{
    w_download mpc $WINETRICKS_SOURCEFORGE/project/mpc-hc/MPC%20HomeCinema%20-%20Win32/MPC-HC%20v1.4.2499.0_32%20bits/MPC-HomeCinema.1.4.2499.0.x86.zip 9f8c4a8e70fa36ffa68f878d13adc8b09b915ece

    mkdir -p "$W_PROGRAMS_X86_UNIX/Media Player Classic"
    cd "$W_PROGRAMS_X86_UNIX/Media Player Classic"
    w_try_unzip -j "$W_CACHE/mpc/MPC-HomeCinema.1.4.2499.0.x86.zip"

    w_declare_exe "$W_PROGRAMS_X86_WIN\Media Player Classic" mpc-hc.exe
}

#----------------------------------------------------------------

w_metadata mspaint apps \
   title="MS Paint" \
   publisher="Microsoft" \
   year="2001" \
   media="download" \
   file1="paintnt.exe" \
   installed_exe1="c:/windows/mspaint.exe"

load_mspaint()
{
    # http://helpforlinux.blogspot.com/2008/12/run-ms-paint-in-linux.html
    w_download mspaint http://download.microsoft.com/download/winntwks40/paint/1/nt4/en-us/paintnt.exe a22c4e367ef9d2cd23f0a8ae8d9ebff5bc1e8a0b
    w_try_unzip "$W_CACHE"/mspaint/paintnt.exe -d "$W_WINDIR_UNIX"

    w_declare_exe "$W_WINDIR_UNIX" "mspaint.exe"
}

#----------------------------------------------------------------

w_metadata psdk2003 apps \
   title="MS Platform SDK 2003" \
   publisher="Microsoft" \
   year="2003" \
   media="download" \
   file1="PSDK-x86.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/Microsoft Platform SDK for Windows Server 2003 R2/SetEnv.Cmd"

load_psdk2003()
{
    w_call mfc42

    # Note: aborts on 64 bit windows with dialog saying "don't run on WoW"
    # http://www.microsoft.com/downloads/details.aspx?familyid=0baf2b35-c656-4969-ace8-e4c0c0716adb
    w_download psdk2003 http://download.microsoft.com/download/f/a/d/fad9efde-8627-4e7a-8812-c351ba099151/PSDK-x86.exe 5c7dc2e1eb902b376d7797cc383fefdfc64ff9c9
    w_warn "This can take up to an hour."

    cd "$W_CACHE"/psdk2003
    # FIXME: says it accepts /q, but that doesn't work, so script this
    # with autohotkey in -q mode.
    w_try $WINE PSDK-x86.exe
}

#----------------------------------------------------------------

w_metadata psdkwin7 apps \
   title="MS Windows 7 SDK (installing just headers and c++ compiler works)" \
   publisher="Microsoft" \
   year="2009" \
   media="download" \
   file1="winsdk_web.exe" \
   installed_exe1="C:/Program Files/Microsoft SDKs/Windows/v7.0/Bin/SetEnv.Cmd"

load_psdkwin7()
{
    # http://www.microsoft.com/downloads/details.aspx?FamilyID=c17ba869-9671-4330-a63e-1fd44e0e2505&displaylang=en
    w_call dotnet20
    if w_workaround_wine_bug 21509 # fixed in wine-1.2
    then
        w_call gdiplus     # work around http://bugs.winehq.org/show_bug.cgi?id=21509
    fi
    w_call mfc42   # need mfc42u, or setup will abort
    # don't have a working unattended recipe.  Maybe we'll have to
    # do an autohotkey script until msft gets its act together:
    # http://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/c053b616-7d5b-405d-9841-ec465a8e21d5
    w_download psdkwin7 http://download.microsoft.com/download/7/A/B/7ABD2203-C472-4036-8BA0-E505528CCCB7/winsdk_web.exe a01dcc67a38f461e80ea649edf1353f306582507
    cd "$W_CACHE"/psdkwin7
    if w_workaround_wine_bug 21596
    then
        w_warn "When given a choice, select only C++ compilers and headers, the other options don't work yet.  See http://bugs.winehq.org/show_bug.cgi?id=21596"
    fi
    w_try $WINE winsdk_web.exe

    # FIXME: don't do this if running on real Windows?
    # Work around bug http://bugs.winehq.org/show_bug.cgi?id=21362
    # Assume user installed in default location
    cat > "$W_TMP"/set-psdk7.reg <<_EOF_
REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows]
"CurrentVersion"="v7.0"
"CurrentInstallFolder"="C:\\\Program Files\\\Microsoft SDKs\\\Windows\\\v7.0\\\"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0]
"InstallationFolder"="C:\\\Program Files\\\Microsoft SDKs\\\Windows\\\v7.0\\\"
"ProductVersion"="7.0.7600.16385.40715"
"ProductName"="Microsoft Windows SDK for Windows 7 (7.0.7600.16385.40715)"
_EOF_
    w_try_regedit "$W_TMP_WIN"\\set-psdk7.reg
}

#----------------------------------------------------------------

w_metadata python26 apps \
   title="Python Interpreter, version 2.6.2" \
   publisher="Python Software Foundaton" \
   year="2009" \
   media="download" \
   file1="python-2.6.2.msi" \
   installed_exe1="c:/Python26/python.exe"

load_python26()
{
    w_download python26 http://www.python.org/ftp/python/2.6.2/python-2.6.2.msi 2d1503b0e8b7e4c72a276d4d9027cf4856b208b8
    w_download python26 $WINETRICKS_SOURCEFORGE/project/pywin32/pywin32/Build%20214/pywin32-214.win32-py2.6.exe eca58f29b810d8e3e7951277ebb3e35ac35794a3
    cd "$W_CACHE"/python26
    w_try $WINE msiexec /i python-2.6.2.msi ALLUSERS=1 $W_UNATTENDED_SLASH_Q

    w_ahk_do "
        SetTitleMatchMode, 2
        run pywin32-214.win32-py2.6.exe
        WinWait, Setup, Wizard will install pywin32
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
             ControlClick Button2   ; next
             WinWait, Setup, Python 2.6 is required
             ControlClick Button3   ; next
             WinWait, Setup, Click Next to begin
             ControlClick Button3   ; next
             WinWait, Setup, finished
             ControlClick Button4   ; Finish
        }
        WinWaitClose
        "
}

#----------------------------------------------------------------

w_metadata python26_comtypes apps \
    title="Comtypes package for Python 2.6" \
    publisher="theller" \
    date="2010" \
    media="download" \
    file1="comtypes-0.6.2.zip" \
    installed_file1="c:/Python26/Lib/site-packages/comtypes-0.6.2-py2.6.egg-info" \
    homepage="http://sourceforge.net/projects/comtypes"

load_python26_comtypes()
{
    w_call python26

    w_download python26_comtypes $WINETRICKS_SOURCEFORGE/comtypes/0.6.2/comtypes-0.6.2.zip b84f4e3050652d494e8c8d9d6d6f221c124ffba9

    cd "$W_TMP"
    w_try_unzip "$W_CACHE/$W_PACKAGE"/comtypes-0.6.2.zip
    cd comtypes-0.6.2
    w_try $WINE "C:\Python26\python.exe" setup.py install
}

#----------------------------------------------------------------

w_metadata  safari apps \
   title="Safari" \
   publisher="Apple" \
   year="2010" \
   media="download" \
   file1="SafariSetup.exe" \
   installed_exe1="$W_PROGRAMS_X86_WIN/Safari/Safari.exe"

load_safari()
{
    w_download safari http://appldnld.apple.com.edgesuite.net/content.info.apple.com/Safari5/061-7138.20100607.Y7U87/SafariSetup.exe e56d5d79d9cfbb85ac46ac78aa497d7f3d8dbc3d

    cd "$W_CACHE"/$W_PACKAGE

    if w_workaround_wine_bug 21146
    then
        w_try mkdir -p "$W_APPDATA_UNIX/Apple Computer/Preferences"
        cat > "$W_APPDATA_UNIX/Apple Computer/Preferences/com.apple.Safari.plist" <<_EOF_
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>LastDisplayedWelcomePageVersionString</key>
        <string>4.0</string>
</dict>
</plist>
_EOF_
    fi

    if test $W_OPT_UNATTENDED = 1
    then
        w_warn "Safari's silent install is broken under wine. See http://bugs.winehq.org/show_bug.cgi?id=23493. You should do a regular install if you want to use Safari."
        w_try $WINE SafariSetup.exe /qn
    else
        w_try $WINE SafariSetup.exe
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Safari" "Safari.exe"
}

#----------------------------------------------------------------

w_metadata steam apps \
   title="Steam" \
   publisher="Valve" \
   year="2010" \
   media="download" \
   file1="SteamInstall.msi" \
   installed_exe1="$W_PROGRAMS_X86_WIN/Steam/Steam.exe"

load_steam()
{
    w_download steam http://storefront.steampowered.com/download/SteamInstall.msi a0ca8791b7b2e96665ee059e03eebbfb3d95be55
    cd "$W_CACHE"/steam
    w_try $WINE msiexec /i SteamInstall.msi $W_UNATTENDED_SLASH_Q
    if ! test -f "$W_FONTSDIR_UNIX/Times.TTF"
    then
        w_warn "Installing corefonts to prvent a Steam crash; see wine bug 22751"
        w_call corefonts
    fi
    if w_workaround_wine_bug 22053
    then
        w_warn "Once Steam is running, disable player notifications and in-game chat in Settings, or games will crash on launch; see wine bug 22053"
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Steam" "Steam.exe"
}

#----------------------------------------------------------------

w_metadata utorrent apps \
   title="µTorrent" \
   publisher="BitTorrent" \
   year="2010" \
   media="download" \
   file1="utorrent.exe" \
   installed_exe1="c:/windows/utorrent.exe"

load_utorrent()
{
    # Torrent client supported on Windows,Mac OSX, Linux through WINE
    # Oct 2010 2.0.4 sha1sum 8382b8a7bc625d68b6efe18a7b9e5488dc0119ee
    # Nov 6 2010 2.0.4 sha1sum 263a91693d0976473cd321cd6f1b0103a814f3ad
    # Dev 17 2010 2.2 sha1sum 0c95bdfba07421fe706b30ee2ec6779217c5dce4, hangs, see wine bug 24946
    w_download utorrent http://download.utorrent.com/2.0.4/utorrent.exe 263a91693d0976473cd321cd6f1b0103a814f3ad

    w_try cp -f "$W_CACHE"/utorrent/utorrent.exe "$W_WINDIR_UNIX"/utorrent.exe
    w_warn "utorrent is now installed to $W_WINDIR_UNIX/utorrent.exe"

    w_declare_exe "c:\\windows" "utorrent.exe"
}

#----------------------------------------------------------------

w_metadata vc2005express apps \
    title="MS Visual C++ 2005 Express" \
    publisher="Microsoft" \
    year="2005" \
    media="download" \
    file1="VC.iso" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Microsoft Visual Studio 8/Common7/IDE/VCExpress.exe"

load_vc2005express()
{
    # Thanks to http://blogs.msdn.com/astebner/articles/551674.aspx for the recipe
    w_call dotnet20
    if w_workaround_wine_bug 20029  # fixed in wine-1.3.9
    then
        w_call msxml6
    fi

    # http://blogs.msdn.com/b/astebner/archive/2006/03/14/551674.aspx
    w_download vc2005express http://go.microsoft.com/fwlink/?linkid=57034 1ae44e4eaf8c61c3a39e573fd6efd9889e940529 VC.iso

    # Unpack ISO (how handy that 7z can do this!)
    cd "$W_TMP"
    w_try 7z x "$W_CACHE"/vc2005express/VC.iso

    if [ $W_UNATTENDED_SLASH_Q ]
    then
        chmod +x Ixpvc.exe
        # Add /qn after ReallySuppress for a really silent install (but then you won't see any errors)

        w_try $WINE Ixpvc /t:"$W_TMP_WIN" /q:a /c:"msiexec /i vcsetup.msi VSEXTUI=1 ADDLOCAL=ALL REBOOT=ReallySuppress"

    else
        if w_workaround_wine_bug 25331
        then
            w_warn "Install fails with wine older than 1.1.35.  With wine-1.3.5 or higher, interactive install fails, but quiet mode (-q option) may work."
        fi
        w_try $WINE setup.exe
        w_ahk_do "
            SetTitleMatchMode, 2
            WinWait, Visual C++ 2005 Express Edition Setup
            WinWaitClose, Visual C++ 2005 Express Edition Setup
        "
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Microsoft Visual Studio 8\\Common7\\IDE" "VCExpress.exe"
}

#----------------------------------------------------------------

w_metadata vlc apps \
   title="VLC media player 1.1.5" \
   publisher="videolan.org" \
   year="2010" \
   media="download" \
   file1="vlc-1.1.5-win32.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/VideoLAN/VLC/vlc.exe" \
   homepage="http://www.videolan.org/vlc/"

load_vlc()
{
    w_download vlc $WINETRICKS_SOURCEFORGE/vlc/vlc-1.1.5-win32.exe 11a14856e07b28d5c637c38f5191915f787fb85e
    cd "$W_CACHE"/vlc
    w_try $WINE vlc-1.1.5-win32.exe $W_UNATTENDED_SLASH_S
    w_declare_exe "$W_PROGRAMS_X86_WIN\\VideoLAN\\VLC" "vlc.exe"
}

#----------------------------------------------------------------

w_metadata wme9 apps \
   title="MS Windows Media Encoder 9 (broken in wine)" \
   publisher="Microsoft" \
   year="2002" \
   media="download" \
   file1="WMEncoder.exe" \
   installed_file1="$W_PROGRAMS_X86_WIN/Windows Media Components/Encoder/wmenc.exe"

load_wme9()
{
    if [ $W_ARCH = win64 ]
    then
        w_die "Installer doesn't support 64-bit architecture."
    fi
    # See also http://www.microsoft.com/downloads/details.aspx?FamilyID=5691ba02-e496-465a-bba9-b2f1182cdf24
    w_download wme9 http://download.microsoft.com/download/8/1/f/81f9402f-efdd-439d-b2a4-089563199d47/WMEncoder.exe 7a3f8781f3e5705651992ef0150ee30bc1295116

    cd "$W_CACHE"/wme9
    w_try $WINE WMEncoder.exe $W_UNATTENDED_SLASH_Q

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Windows Media Components\\Encoder" "wmenc.exe"
}

#----------------------------------------------------------------

# helper - not useful by itself
load_wm9codecs()
{
    # Note: must install WMP9 or 10 first, or installer will complain and abort.

    # See http://www.microsoft.com/downloads/details.aspx?FamilyID=06fcaab7-dcc9-466b-b0c4-04db144bb601
    w_download wm9codecs http://download.microsoft.com/download/5/c/2/5c29d825-61eb-4b16-8eb8-58367d0464d5/WM9Codecs9x.exe 8b76bdcbea0057eb12b7966edab4b942ddacc253
    cd "$W_CACHE/wm9codecs"
    w_set_winver win2k
    w_try $WINE WM9Codecs9x.exe $W_UNATTENDED_SLASH_Q
}

w_metadata wmp9 apps \
   title="Windows Media Player 9" \
   publisher="Microsoft" \
   year="2003" \
   media="download" \
   file1="MPSetup.exe" \
   installed_file1="$W_SYSTEM32_DLLS"/l3codeca.acm

load_wmp9()
{
    w_skip_windows wmp9 && return

    # Not really expected to work well yet; see
    # http://appdb.winehq.org/appview.php?versionId=1449

    if [ $W_ARCH = win64 ]
    then
        w_die "Installer doesn't support 64-bit architecture."
    fi

    w_call wsh57

    w_set_winver win2k

    # See also http://www.microsoft.com/windows/windowsmedia/player/9series/default.aspx
    w_download wmp9 http://download.microsoft.com/download/1/b/c/1bc0b1a3-c839-4b36-8f3c-19847ba09299/MPSetup.exe 580536d10657fa3868de2869a3902d31a0de791b

    # Have to run twice; see http://bugs.winehq.org/show_bug.cgi?id=1886
    cd "$W_CACHE"/wmp9
    w_try $WINE MPSetup.exe $W_UNATTENDED_SLASH_Q
    w_try $WINE MPSetup.exe $W_UNATTENDED_SLASH_Q

    # Disable WMP's services, since they depend on unimplemented stuff, they trigger the GUI debugger several times
    w_try_regedit /D "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Cdr4_2K"
    w_try_regedit /D "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Cdralw2k"

    w_unset_winver

    load_wm9codecs

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Windows Media Player" "wmplayer.exe"
}

#----------------------------------------------------------------

w_metadata wmp10 apps \
   title="Windows Media Player 10" \
   publisher="Microsoft" \
   year="2006" \
   media="download" \
   file1="MP10Setup.exe" \
   installed_file1="$W_SYSTEM32_DLLS"/l3codecp.acm

load_wmp10()
{
    # FIXME: what versions of windows are really bundled with wmp10?
    w_skip_windows wmp10 && return

    # See http://appdb.winehq.org/appview.php?iVersionId=3212
    w_call wsh57

    # http://www.microsoft.com/downloads/en/details.aspx?FamilyID=b446ae53-3759-40cf-80d5-cde4bbe07999
    w_download wmp10 http://download.microsoft.com/download/1/2/A/12A31F29-2FA9-4F50-B95D-E45EF7013F87/MP10Setup.exe 69862273a5d9d97b4a2e5a3bd93898d259e86657

    # Crashes on exit, but otherwise ok; see http://bugs.winehq.org/show_bug.cgi?id=12633
    cd "$W_CACHE"/wmp10
    w_try $WINE MP10Setup.exe $W_UNATTENDED_SLASH_Q

    # Disable WMP's services, since they depend on unimplemented stuff, they trigger the GUI debugger several times
    w_try_regedit /D "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Cdr4_2K"
    w_try_regedit /D "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Cdralw2k"

    load_wm9codecs

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Windows Media Player" "wmplayer.exe"
}

#----------------------------------------------------------------
# Benchmarks
#----------------------------------------------------------------

w_metadata 3dmark2000 benchmarks \
    title="3DMark2000" \
    publisher="MadOnion.com" \
    year="2000" \
    media="download" \
    file1="3dmark2000_v11_100308.exe" \
    installed_file1="$W_PROGRAMS_X86_WIN/MadOnion.com/3DMark2000/3DMark2000.exe"

load_3dmark2000()
{
    # http://www.futuremark.com/download/3dmark2000/
    if ! test -f "$W_CACHE/$W_PACKAGE/3dmark2000_v11_100308.exe"
    then
        w_download $W_PACKAGE http://www.ocinside.de/download/3dmark2000_v11_100308.exe b0400d59cfd45d8c8893d3d4edc58b6285ee1502
    fi

    cd "$W_TMP"
    mkdir $W_PACKAGE
    cd $W_PACKAGE
    w_try_unzip "$W_CACHE/$W_PACKAGE"/3dmark2000_v11_100308.exe
    w_ahk_do "
        SetTitleMatchMode, 2
        run Setup.exe
        WinWait Welcome
        ;ControlClick Button1  ; Next
        Sleep 1000
        Send {Enter}           ; Next
        WinWait License
        ;ControlClick Button2  ; Yes
        Sleep 1000
        Send {Enter}           ; Yes
        ;WinWaitClose ahk_class #32770 ; License
        WinWait ahk_class #32770, Destination
        ;ControlClick Button1  ; Next
        Sleep 1000
        Send {Enter}           ; Next
        ;WinWaitClose ahk_class #32770 ; Destination
        WinWait, Start
        ;ControlClick Button1  ; Next
        Sleep 1000
        Send {Enter}           ; Next
        WinWait Registration
        ControlClick Button1  ; Next
        WinWait Complete
        Sleep 1000
        ControlClick Button1  ; Unclick View Readme
        ;ControlClick Button4  ; Finish
        Send {Enter}           ; Finish
        WinWaitClose
    "

    cat > "$W_DRIVE_C/run-$W_PACKAGE.bat" <<__EOF__
${programfilesdrive}:
cd "$W_PROGRAMS_X86_WIN\MadOnion.com\3DMark2000"
REM possible wine cmd bug: "3dmark2000" aborts, but ".\3dmark2000" works
.\3DMark2000
__EOF__

}

#----------------------------------------------------------------

w_metadata 3dmark2001 benchmarks \
    title="3DMark2001" \
    publisher="MadOnion.com" \
    year="2001" \
    media="download" \
    file1="3dmark2001se_330_100308.exe" \
    installed_file1="$W_PROGRAMS_X86_WIN/MadOnion.com/3DMark2001 SE/3DMark2001SE.exe"

load_3dmark2001()
{
    # http://www.futuremark.com/download/3dmark2001/
    if ! test -f "$W_CACHE/$W_PACKAGE"/3dmark2001se_330_100308.exe
    then
        w_download $W_PACKAGE http://www.ocinside.de/download/3dmark2001se_330_100308.exe 643bacbcc1615bb4f46d3b045b1b8d78371a6b54
    fi

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        SetTitleMatchMode, 2
        run 3dmark2001se_330_100308.exe
        WinWait ahk_class #32770 ; welcome
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            ControlClick Button2  ; Next
            sleep 5000
            WinWait ahk_class #32770 ; License
            ControlClick Button2  ; Next
            WinWait ahk_class #32770, Destination
            ControlClick Button1  ; Next
            WinWait ahk_class #32770, Start
            ControlClick Button1  ; Next
            WinWait,, Registration
            ControlClick Button2  ; Next
        }
        WinWait,, Complete
        if ( u > 0 ) {
            ControlClick Button1  ; Unclick View Readme
            ControlClick Button4  ; Finish
        }
        WinWaitClose
    "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\MadOnion.com\\3DMark2001 SE" "3DMark2001SE.exe"
}

#----------------------------------------------------------------

w_metadata 3dmark03 benchmarks \
    title="3D Mark 03" \
    publisher="Futuremark" \
    year="2003" \
    media="download" \
    file1="3DMark03_v360_1901.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Futuremark/3DMark03/3DMark03.exe"

load_3dmark03()
{
    # http://www.futuremark.com/benchmarks/3dmark03/download/
    if ! test -f "$W_CACHE/$W_PACKAGE/3DMark03_v360_1901.exe"
    then
        w_download $W_PACKAGE http://www.bulletproofnerds.com/uploadedfiles/futuremark/3DMark03_v360_1901.exe 46a439101ddbbe3c9563b5e9651cb61b46ce0619
    fi

    cd "$W_CACHE/$W_PACKAGE"
    w_warn "Don't use mouse while this installer is running.  Sorry..."
    # This old installer doesn't seem to be scriptable the usual way, so spray and pray.
    w_ahk_do "
        SetTitleMatchMode, 2
        run 3DMark03_v360_1901.exe
        WinWait 3DMark03 - InstallShield Wizard, Welcome
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            WinActivate
            Send {Enter}
            Sleep 2000
            WinWait 3DMark03 - InstallShield Wizard, License
            WinActivate
            ; Accept license
            Send a
            Send {Enter}
            Sleep 2000
            ; Choose Destination
            Send {Enter}
            Sleep 2000
            ; Begin install
            Send {Enter}
            ; Wait for install to finish
            WinWait 3DMark03, Registration
            ; Purchase later
            Send {Tab}
            Send {Tab}
            Send {Enter}
        }
        WinWait, 3DMark03 - InstallShield Wizard, Complete
        if ( u > 0 ) {
            ; Uncheck readme
            Send {Space}
            Send {Tab}
            Send {Tab}
            Send {Enter}
        }
        WinWaitClose, 3DMark03 - InstallShield Wizard, Complete
    "
    w_declare_exe "$W_PROGRAMS_X86_WIN\\Futuremark\\3DMark03" "3DMark03.exe"
}

#----------------------------------------------------------------

w_metadata 3dmark05 benchmarks \
    title="3D Mark 05" \
    publisher="Futuremark" \
    year="2005" \
    media="download" \
    file1="3DMark05_v130_1901.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Futuremark/3DMark05/3DMark05.exe"

load_3dmark05()
{
    # http://www.futuremark.com/download/3dmark05/
    if ! test -f "$W_CACHE/$W_PACKAGE/3DMark05_v130_1901.exe"
    then
        w_download $W_PACKAGE http://www.bulletproofnerds.com/uploadedfiles/futuremark/3DMark05_v130_1901.exe 8ad6bc2917e22edf5fc95d1fa96cc82515093fb2
    fi

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        run 3DMark05_v130_1901.exe
        WinWait ahk_class #32770, Welcome
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Send {Enter}
            WinWait, ahk_class #32770, License
            ControlClick Button1 ; Accept
            ControlClick Button4 ; Next
            WinWait, ahk_class #32770, Destination
            ControlClick Button1 ; Next
            WinWait, ahk_class #32770, Install
            ControlClick Button1 ; Install
            WinWait, ahk_class #32770, Purchase
            ControlClick Button4 ; Later
        }
        WinWait, ahk_class #32770, Complete
        if ( u > 0 ) {
            ControlClick Button1 ; Uncheck view readme
            ControlClick Button3 ; Finish
        }
        WinWaitClose, ahk_class #32770, Complete
    "
    ARGS=""
    if w_workaround_wine_bug 22392
    then
        w_warn "You must run the app with the -nosysteminfo option to avoid a crash on startup"
        ARGS="-nosysteminfo"
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Futuremark\\3DMark05" "3DMark05 $ARGS"
}

#----------------------------------------------------------------

w_metadata 3dmark06 benchmarks \
    title="3D Mark 06" \
    publisher="Futuremark" \
    year="2006" \
    media="download" \
    file1="3DMark06_v120_1901.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Futuremark/3DMark06/3DMark06.exe"

load_3dmark06()
{
    # http://www.futuremark.com/benchmarks/3dmark06/download/
    if ! test -f "$W_CACHE/$W_PACKAGE/3DMark06_v120_1901.exe"
    then
        w_download $W_PACKAGE http://www.bulletproofnerds.com/uploadedfiles/futuremark/3DMark06_v120_1901.exe 2e4a52d5b0f7caebd7b4407dfa9e258ac623b5dd
    fi

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        run 3DMark06_v120_1901.exe
        WinWait ahk_class #32770, Welcome
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Send {Enter}
            WinWait, ahk_class #32770, License
            ControlClick Button1 ; Accept
            ControlClick Button4 ; Next
            WinWait, ahk_class #32770, Destination
            ControlClick Button1 ; Next
            WinWait, ahk_class #32770, Install
            ControlClick Button1 ; Install
            WinWait ahk_class OpenAL Installer
            ControlClick Button2 ; OK
            WinWait ahk_class #32770
            ControlClick Button1 ; OK
            WinWait, ahk_class #32770, Purchase
            ControlClick Button4 ; Later
        }
        WinWait, ahk_class #32770, Complete
        if ( u > 0 ) {
            ControlClick Button1 ; Uncheck view readme
            ControlClick Button3 ; Finish
        }
        WinWaitClose, ahk_class #32770, Complete
    "

    if w_workaround_wine_bug 9210
    then
        w_warn "You may need to apply the patch in http://bugs.winehq.org/show_bug.cgi?id=9210 to fix pCaps->MaxPointSize, or the benchmark will w_warn that shader model 2.0 is not present, and refuse to run."
    fi

    if w_workaround_wine_bug 22393
    then
        # "Demo" button doesn't work without this
        w_call d3dx9_28
        w_call d3dx9_36
    fi

    ARGS=""
    if w_workaround_wine_bug 22392
    then
        w_warn "You must run the app with the -nosysteminfo option to avoid a crash on startup"
        ARGS="-nosysteminfo"
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Futuremark\\3DMark06" "3DMark06 $ARGS"
}

#----------------------------------------------------------------
# Games
#----------------------------------------------------------------

w_metadata algodoo_demo games \
    title="Algodoo Demo" \
    publisher="Algoryx" \
    year="2009" \
    media="download" \
    file1="Algodoo_1_7_1-Win32.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Algodoo/Algodoo.exe"

load_algodoo_demo()
{
    w_download $W_PACKAGE  http://www.algodoo.com/download/Algodoo_1_7_1-Win32.exe caa73e73669a8787652a6bed123bbe2682152f12

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        ; This one's funny... on Wine, keyboard works once you click manually, but until then, only ControlClick seems to work.
        run, Algodoo_1_7_1-Win32.exe
        SetTitleMatchMode, 2
        winwait, Algodoo, Welcome
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            ControlClick, TNewButton1
            winwait, Algodoo, License
            ;send {Tab}a{Space}{Enter}
            ControlClick, TNewRadioButton1  ; Accept
            ControlClick, TNewButton2  ; Next
            winwait, Algodoo, Destination
            ;send {Enter}
            ControlClick, TNewButton3  ; Next
            winwait, Algodoo, Folder
            ;send {Enter}
            ControlClick, TNewButton4  ; Next
            winwait, Algodoo, Select Additional Tasks
            ;send {Enter}
            ControlClick, TNewButton4  ; Next
            winwait, Algodoo, Ready to Install
            ;send {Enter}
            ControlClick, TNewButton4  ; Next
            winwait, Algodoo, Completing
            sleep 500
            send {Space}{Tab}{Space}{Tab}{Space}{Enter}   ; decline to run app or view tutorials
        }
        WinWaitClose, Algodoo, Completing
    "

    # Since we declined the msvc runtime installer (right?), we have to do it here
    if w_workaround_wine_bug 23815
    then
        w_call vcrun2008
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Algodoo" "Algodoo.exe"
}

#----------------------------------------------------------------

w_metadata amnesia_tdd_demo games \
    title="Amnesia: The Dark Descent Demo" \
    publisher="Frictional Games" \
    year="2010" \
    media="manual_download" \
    file1="amnesia_tdd_demo_1.0.1.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Amnesia - The Dark Descent Demo/redist/Amnesia.exe"

load_amnesia_tdd_demo()
{
    w_download_manual $W_PACKAGE "http://www.amnesiagame.com/#demo" amnesia_tdd_demo_1.0.1.exe 0bf0bc6e9c8ea76f1c44582d9302a9b22d31d1b6

    cd "$W_CACHE/$W_PACKAGE"

    w_ahk_do "
        SetTitleMatchMode, 2
        run amnesia_tdd_demo_1.0.1.exe
        WinWait,Select Setup Language,language
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Sleep 2000
            ;ControlClick TNewButton1 ; OK
            send {Enter}              ; button click fails on vista?
            WinWait,Setup - Amnesia - The Dark Descent Demo,Welcome
            Sleep 500
            ControlClick TNewButton1 ; Next
            WinWait,Setup - Amnesia - The Dark Descent Demo,License
            Sleep 500
            ControlClick TNewRadioButton1 ; agree
            Sleep 500
            ControlClick TNewButton2 ; Next
            WinWait,Setup - Amnesia - The Dark Descent Demo,Destination
            Sleep 500
            ControlClick TNewButton3 ; Next
            WinWait,Folder Does Not Exist,created
            Sleep 500
            ControlClick Button1 ; OK
            WinWait,Setup - Amnesia - The Dark Descent Demo,should
            Sleep 500
            ControlClick TNewButton4 ; Next
            WinWait,Setup - Amnesia - The Dark Descent Demo,should
            Sleep 500
            ControlClick TNewButton4 ; Next
            WinWait,Setup - Amnesia - The Dark Descent Demo,installing
            Sleep 500
            ControlClick TNewButton4 ; Install
        }
        WinWait,Setup - Amnesia - The Dark Descent Demo,finished
        if ( u > 0 ) {
            Sleep 500
            ControlClick TNewButton4 ; Finish
        }
        WinWaitClose,Setup - Amnesia - The Dark Descent Demo,finished
    "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Amnesia - The Dark Descent Demo\\redist" "Amnesia.exe"
}

#----------------------------------------------------------------

w_metadata aoe3_demo games \
    title="Age of Empires III" \
    publisher="Microsoft" \
    year="2005" \
    media="download" \
    file1="aoe3trial.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Microsoft Games/Age of Empires III Trial/age3.exe"

load_aoe3_demo()
{

    w_download $W_PACKAGE "http://download.microsoft.com/download/a/5/2/a525997e-8423-435b-b694-08118d235064/aoe3trial.exe" \
        2b0a123243092d79f910db5691d99d469f7c17c3

    if w_workaround_wine_bug 24897
    then
        w_call msxml4
    fi

    cd "$W_CACHE/$W_PACKAGE"

    w_ahk_do "
        SetTitleMatchMode, 2
        run aoe3trial.exe
        WinWait,Empires,Welcome
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            winactivate          ; else next button click ignored on vista?
            Sleep 500
            ControlClick Button1 ; Next
            WinWait,Empires,Please
            Sleep 500
            ControlClick Button4 ; Next
            WinWait,Empires,Complete
            Sleep 500
            ControlClick Button4 ; Finish
        }
        WinWaitClose
    "

    if w_workaround_wine_bug 24911
    then
        # On some systems, only quartz is needed?
        # appdb says that l3codecx is also needed?
        w_call devenum
        w_call dmsynth
        w_call quartz
    fi

    if w_workaround_wine_bug 24912
    then
        # kill off lingering installer
        w_ahk_do "
            SetTitleMatchMode, 2
            WinKill,Empires
        "
        # or should we just do wineserver -k, like fable_tlc does?
        PID=`ps augxw | grep IDriver | grep -v grep | awk '{print $2}'`
        kill $PID
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Microsoft Games\\Age of Empires III Trial" "age3.exe"
}

#----------------------------------------------------------------

w_metadata aoe_demo games \
    title="Age of Empires Demo" \
    publisher="Microsoft" \
    year="1997" \
    media="download" \
    file1="MSAoE.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Microsoft Games/Age of Empires Trial/empires.exe"

load_aoe_demo()
{
    w_download $W_PACKAGE http://download.microsoft.com/download/aoe/Trial/1.0/WIN98/EN-US/MSAoE.exe 23630a65ce4133038107f3175f8fc54a914bc2f3

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        run, MSAoE.exe
        SetTitleMatchMode, 2
        winwait, Microsoft Age of Empires Trial Version
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            ControlClick, Button1
            winwait, End User License Agreement
            ControlClick, Button1
            winwait, Microsoft Age of Empires Trial Version, Setup will install
            ControlClick Button2
            winwait, Microsoft Age of Empires Trial Version, Setup has successfully
            ControlClick Button1
        }
        WinWaitClose, Microsoft Age of Empires Trial Version
    "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Microsoft Games\\Age of Empires Trial" "empires"
}

#----------------------------------------------------------------

w_metadata bioshock_demo games \
    title="Bioshock Demo" \
    publisher="2K Games" \
    year="2007" \
    media="download" \
    file1="nzd_BioShockPC.zip" \
    installed_exe1="$W_PROGRAMS_X86_WIN/2K Games/BioShock Demo/Builds/Release/Bioshock.exe"

load_bioshock_demo()
{
    w_download $W_PACKAGE http://us.download.nvidia.com/downloads/nZone/demos/nzd_BioShockPC.zip 7a19186602cec5210e4505b58965e8c04945b3cf

    w_try unzip "$W_CACHE/$W_PACKAGE/nzd_BioShockPC.zip" -d "$W_TMP/$W_PACKAGE"
    cd "$W_TMP/$W_PACKAGE/BioShock PC Demo"

    w_ahk_do "
        SetTitleMatchMode, 2
        run setup.exe
        winwait, BioShock Demo - InstallShield Wizard, Choose Setup Language
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 2000
            ControlClick, Button3
            ControlClick, Button3
            winwait, BioShock Demo - InstallShield Wizard, Welcome
            sleep 1000
            ControlClick, Button1
            winwait, BioShock Demo - InstallShield Wizard, Please read
            sleep 1000
            ControlClick, Button5
            sleep 1000
            ControlClick, Button2
            winwait, BioShock Demo - InstallShield Wizard, Select the setup type
            sleep 1000
            ControlClick, Button2
            winwait, BioShock Demo - InstallShield Wizard, Click Install to begin
            ControlClick, Button1
        }
        winwait, BioShock Demo - InstallShield Wizard, The InstallShield Wizard has successfully installed BioShock
        if ( u > 0 ) {
            sleep 1000
            ControlClick, Button2     ; don't launch
            ControlClick, Button6     ; don't show readme
            send {Enter}              ; finish
        }
        winwaitclose
        sleep 3000 ; wait for splash screen to close
    "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\2K Games\\BioShock Demo\\Builds\\Release" "Bioshock.exe"
}

#----------------------------------------------------------------

w_metadata  bfbc2 games \
   title="Battlefield Bad Company 2" \
   publisher="EA" \
   year="2010" \
   media="dvd" \
   file1="BFBC2.iso"

load_bfbc2()
{
    w_mount BFBC2
    w_read_key
    w_ahk_do "
        SetTitleMatchMode, 2
        run ${W_ISO_MOUNT_LETTER}:setup.exe
        winwait, Bad Company, English
        ControlClick, Next, Bad Company
        winwait, Bad Company, Registration Code
        send {RAW}$W_KEY
        ControlClick, Next, Bad Company, Registration Code
        winwait, Bad Company, Setup Wizard will install
        ControlClick, Button1, Bad Company, Setup Wizard
        winwait, Bad Company, License Agreement
        ControlClick, Button1, Bad Company, License Agreement
        ControlClick, Button3, Bad Company, License Agreement
        winwait, Bad Company, End-User License Agreement
        ControlClick, Button1, Bad Company, License Agreement
        ControlClick, Button3, Bad Company, License Agreement
        winwait, Bad Company, Destination Folder
        ControlClick, Button1, Bad Company, Destination Folder
        winwait, Bad Company, Ready to install
        ControlClick, Install, Bad Company, Ready to install
        winwait, Authenticate Battlefield
        ControlClick, Disc authentication, Authenticate Battlefield
        ControlClick, Button4, Authenticate Battlefield
        winwait, Bad Company, PunkBuster
        ControlClick, Button4, Bad Company, PunkBuster
        ControlClick, Finish, Bad Company
    "

    w_warn "Patching to latest version..."

    cd "$W_PROGRAMS_X86_UNIX/Electronic Arts/Battlefield Bad Company 2"
    w_ahk_do "
        SetTitleMatchMode, 2
        run, BFBC2Updater.exe
        winwait, Updater, have to update to
        ControlClick, Yes, Updater, have to update
        winwait, Updater, successfully updated
        ControlClick,No, Updater, successfully updated
    "

    if w_workaround_wine_bug 22762
    then
        # FIXME: does this directory name change in win7?
        cd "$W_DRIVE_C/users/$USERNAME/My Documents"
        if test -f BFBC2/settings.ini
        then
            mv BFBC2/settings.ini BFBC2/oldsettings.ini
            sed 's,DxVersion=auto,DxVersion=9,;
                 s,Fullscreen=true,Fullscreen=false,' BFBC2/oldsettings.ini > BFBC2/settings.ini
        else
            mkdir -p BFBC2
            echo "[Graphics]" > BFBC2/settings.ini
            echo "DxVersion=9" >> BFBC2/settings.ini
        fi
    fi

    if w_workaround_wine_bug 22961
    then
        w_warn 'If the game says "No CD/DVD error", try "sudo mount -o remount,unhide,uid=`uid -u`".  See http://bugs.winehq.org/show_bug.cgi?id=22961 for more info.'
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Electronic Arts\\Battlefield Bad Company 2" "BFBC2Game.exe"
}

#----------------------------------------------------------------

w_metadata bladekitten_demo games \
    title="Blade Kitten Demo" \
    publisher="Krome Studios Pty Ltd." \
    year="2010" \
    media="download" \
    file1="BladeKittenDemoInstall.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Krome Studios/Blade Kitten Demo/BladeKitten_Demo.exe"

load_bladekitten_demo()
{
    if ! test -f "$W_CACHE/$W_PACKAGE/BladeKittenDemoInstall.exe"
    then
        w_download $W_PACKAGE "http://downloads.megagames.com/download.php?file=BladeKittenDemoInstall.exe" 8c41706ff3ad029317e5eb6853c34732498d97c7 BladeKittenDemoInstall.exe
    fi

    cp "$W_CACHE/$W_PACKAGE"/BladeKittenDemoInstall.exe "$W_TMP"
    cd "$W_TMP"
    w_ahk_do "
        ; This script always gives full window title, so no need to set a different title match mode
        run BladeKittenDemoInstall.exe
        WinWait Blade Kitten Demo Install Package
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Sleep 500
            ControlClick Button2 ;  Install
            WinWait Blade Kitten Demo, Next
            Sleep 500
            ControlClick Button1
            WinWait Blade Kitten Demo, Cost
            Sleep 500
            ControlClick Button1  ; Next
            WinWait Blade Kitten Demo, ready
            Sleep 500
            ControlClick Button1 ;  Next
            ; Note - in older versions of wine, the directx installer may take 6-10 minutes at this point
        }
        WinWaitClose
        WinWait Blade Kitten Demo, Complete
        if ( u > 0 ) {
            Sleep 500
            ControlClick Button1 ;  Close
        }
        WinWaitClose
    "

    if w_workaround_wine_bug 24681
    then
        w_set_app_winver BladeKitten_Demo.exe win2k
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Krome Studios\\Blade Kitten Demo" "BladeKitten_Demo.exe"
}

#----------------------------------------------------------------

# http://appdb.winehq.org/objectManager.php?sClass=version&iId=9320
w_metadata  blobby_volley games \
   title="Blobby Volley" \
   publisher="Daniel Skoraszewsky" \
   year="2000" \
   media="manual_download" \
   file1="blobby.zip" \
   installed_exe1="c:/BlobbyVolley/volley.exe"

load_blobby_volley()
{
    w_download_manual blobby_volley http://www.chip.de/downloads/Blobby-Volley_12990993.html blobby.zip c7057c77a5009a88d9d877e17a63b5536ebeb177

    mkdir -p "$W_DRIVE_C/BlobbyVolley"
    cd "$W_CACHE/$W_PACKAGE"
    w_try_unzip blobby.zip -d "$W_DRIVE_C/BlobbyVolley"
    w_declare_exe "c:\\BlobbyVolley" "volley.exe"

    if w_workaround_wine_bug 4432
    then
        w_warn "You may need to apply a patch, see http://bugs.winehq.org/show_bug.cgi?id=4432#c15"
    fi
}

#----------------------------------------------------------------

w_metadata cod_demo games \
    title="Call of Duty demo" \
    publisher="Activision" \
    year="2003" \
    media="download" \
    file1="Call_Of_Duty_Demo.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Call of Duty Single Player Demo/CoDSP.exe"

load_cod_demo()
{
    w_download $W_PACKAGE "http://gamedaily.newaol.com/pub/Call_Of_Duty_Demo.exe" 1c480a1e64a80f7f97fd0acd9582fe190c64ad8e

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        SetTitleMatchMode, 2
        run Call_Of_Duty_Demo.exe
        WinWait,Call of Duty Single Player Demo,Welcome
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            ControlClick Button1 ; next
            WinWait,Call of Duty Single Player Demo,License
            sleep 1000
            WinActivate
            send A               ; I Agree
            WinWait,Call of Duty Single Player Demo,System
            sleep 1000
            send n               ; Next
            WinWait,Call of Duty Single Player Demo,Location
            sleep 1000
            send {Enter}
            WinWait,Call of Duty Single Player Demo,Select
            sleep 1000
            send n
            WinWait,Call of Duty Single Player Demo,Start
            sleep 1000
            send i               ; Install
            WinWait,Create Shortcut
            sleep 1000
            send n               ; No
        }
        WinWait,Call of Duty Single Player Demo, Complete
        if ( u > 0 ) {
            sleep 1000
            send {Enter}         ; Finish
        }
        WinWaitClose
    "

    if w_workaround_wine_bug 21558
    then
        # Work around a buffer overflow - not really Wine's fault
        setvar="@if not defined %__GL_ExtensionStringVersion% then echo \"If you get a buffer overflow error, set __GL_ExtensionStringVersion=17700 before starting Wine.  See http://bugs.winehq.org/show_bug.cgi?id=21558.\""
    else
        setvar=
    fi
    cat > "$W_DRIVE_C/run-$W_PACKAGE.bat" <<__EOF__
$setvar
${programfilesdrive}:
cd "$W_PROGRAMS_X86_WIN\\Call of Duty Single Player Demo"
CoDSP.exe
__EOF__

}

#----------------------------------------------------------------

w_metadata cod1 games \
    title="Call of Duty" \
    publisher="Activision" \
    year="2003" \
    media="dvd" \
    file1="COD1.iso" \
    file2="CoD2.iso"

load_cod1()
{
    # FIXME: port load_harder from winetricks and use it when caching first disc
    w_mount COD1

    w_read_key

    __GL_ExtensionStringVersion=17700 w_ahk_do "
        SetTitleMatchMode, 2
        run ${W_ISO_MOUNT_LETTER}:setup.exe
        WinWait, CD Key, enter
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            send {Raw}$KEY
            ControlClick Button1
            WinWait, CD Key, valid
            ControlClick Button1
            WinWait, Call of Duty, Welcome
            ControlClick Button1
            WinWait, Call of Duty, License
            ControlClick Button3
            WinWait, Call of Duty, Minimum
            ControlClick Button4
            WinWait, Call of Duty, Location
            ControlClick Button1
            WinWait, Call of Duty, Folder
            ControlClick Button1
            WinWait, Call of Duty, Start
            ControlClick Button1
        }
        WinWait, Insert CD, Please insert the Call of Duty CD 2
        "

    $WINE eject ${W_ISO_MOUNT_LETTER}:
    w_mount CoD2

    w_ahk_do "
        SetTitleMatchMode, 2
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Send {Enter}    ;continue installation
        }
        WinWait, Insert CD, Please insert the Call of Duty CD 1
    "

    $WINE eject ${W_ISO_MOUNT_LETTER}:
    w_mount COD1

    w_ahk_do "
        SetTitleMatchMode, 2
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Send {Enter}    ;finalize install
            WinWait, Create Shortcut, Desktop
            ControlClick Button1
            WinWait, DirectX, Call    ;directx 9
            ControlClick Button6
            ControlClick Button1
            WinWait, Confirm DX settings, Are
            ControlClick Button2
        }
        ; handle crash here
        WinWait, Installation Complete, Congratulations!
        if ( u > 0 ) {
            ControlClick Button1
        }
        WinWaitClose
    "
    $WINE eject ${W_ISO_MOUNT_LETTER}:

    if w_workaround_wine_bug 21558
    then
        # Work around a buffer overflow - not really Wine's fault
        setvar="@if not defined %__GL_ExtensionStringVersion% then echo \"If you get a buffer overflow error, set __GL_ExtensionStringVersion=17700 before starting Wine.  See http://bugs.winehq.org/show_bug.cgi?id=21558.\""
    else
        setvar=
    fi
    cat > "$W_DRIVE_C/run-$W_PACKAGE.bat" <<__EOF__
$setvar
${programfilesdrive}:
cd "$W_PROGRAMS_X86_WIN\\Call of Duty"
CoDSP.exe
__EOF__

    w_warn "This game is copy-protected, and requires the real disc in a real drive to run."
}

#----------------------------------------------------------------

w_metadata cod4mw_demo games \
    title="Call of Duty 4 Modern Warfare" \
    publisher="Activision" \
    year="2007" \
    media="download" \
    file1="CoD4MWDemoSetup_v2.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Activision/Call of Duty 4 - Modern Warfare Demo/iw3sp.exe"

load_cod4mw_demo()
{
    w_download $W_PACKAGE "http://gamedaily.newaol.com/pub/CoD4MWDemoSetup_v2.exe" 690a5f789a44437ed10784acfdd6418ca4a21886

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        SetTitleMatchMode, 2
        run, CoD4MWDemoSetup_v2.exe
        WinWait,Modern Warfare,Welcome
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Sleep 500
            ControlClick Button1 ; Next
            WinWait,Modern Warfare, License
            Sleep 500
            ControlClick Button5 ; accept
            Sleep 2000
            ControlClick Button2 ; Next
            WinWait,Modern Warfare, System Requirements
            Sleep 500
            ControlClick Button1 ; Next
            Sleep 500
            ControlClick Button4 ; Next
            WinWait,Modern Warfare, Typical
            Sleep 500
            ControlClick Button4 ; License
            Sleep 500
            ControlClick Button1 ; Next
            WinWait,Question, shortcut
            Sleep 500
            ControlClick Button1 ; Yes
            WinWait,Microsoft DirectX Setup, license
            Sleep 500
            ControlClick Button1 ; Yes
            WinWait,Modern Warfare, finished
            Sleep 500
            ControlClick Button1 ; Finished
        }
        WinWaitClose,WinZip Self-Extractor - CoD4MWDemoSetup_v2
    "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Activision\\Call of Duty 4 - Modern Warfare Demo" "iw3sp.exe"
}

#----------------------------------------------------------------

w_metadata civ4_demo games \
   title="Civilization IV Demo" \
   publisher="Firaxis Games" \
   year="2005" \
   media="manual_download" \
   file1="Civilization4_Demo.zip" \
   installed_file1="$W_PROGRAMS_X86_WIN/Firaxis Games/Sid Meier's Civilization 4 Demo/Civilization4.exe"

load_civ4_demo()
{
    w_download_manual civ4_demo http://download.cnet.com/Civilization-IV-demo/3000-7489_4-10465206.html Civilization4_Demo.zip b54f1e5d0a1c2d1ef456d0c20098c23bbb6a0ea7

    cd "$W_CACHE/$W_PACKAGE"
    w_try_unzip Civilization4_Demo.zip -d "$W_TMP"
    cd "$W_TMP/$W_PACKAGE"
    chmod +x setup.exe
    w_ahk_do "
        SetTitleMatchMode, 2
        run, setup.exe
        winwait, Choose Setup Language
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            Send {enter}
            winwait, Civilization 4, Welcome
            ControlClick &Next >, Civilization 4
            winwait, Civilization 4, I &accept the terms of the license agreement
            ControlClick I &accept, Civilization 4
            ControlClick &Next >, Civilization 4
            winwait, Civilization 4, Express Install
            ControlClick &Next >, Civilization 4
            winwait, Civilization 4, begin installation
            ControlClick &Install, Civilization 4
            winwait, Civilization 4, InstallShield Wizard Complete
            ControlClick Finish, Civilization 4
        }
        winwaitclose
    "

    if w_workaround_wine_bug 6856
    then
        w_call msxml3
    fi
    if w_workaround_wine_bug 6856 # part 2, still need to file a bug
    then
        w_call d3dx9_26
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Firaxis Games\\Sid Meier's Civilization 4 Demo" "Civilization4.exe"
}

#----------------------------------------------------------------

w_metadata darknesswithin2_demo games \
    title="Darkness Within 2 Demo" \
    publisher="Zoetrope Interactive" \
    year="2010" \
    media="manual_download" \
    file1="DarknessWithin2Demo.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Iceberg Interactive/Darkness Within 2 Demo/DarkLineage.exe"

load_darknesswithin2_demo()
{
    w_download_manual $W_PACKAGE http://www.bigdownload.com/games/darkness-within-2-the-dark-lineage/pc/darkness-within-2-the-dark-lineage-demo DarknessWithin2Demo.exe

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        SetTitleMatchMode, 2
        run, DarknessWithin2Demo.exe
        winwait, Darkness Within, will install
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            ControlClick, TNewButton1
            winwait, Darkness, License
            ControlClick, TNewRadioButton1
            ControlClick, TNewButton2
            winwait, Darkness, Location
            ControlClick, TNewButton3
            winwait, Darkness, shortcuts
            ControlClick, TNewButton4
            winwait, Darkness, additional
            ControlClick, TNewButton4
            winwait, Darkness, Ready to Install
            ControlClick, TNewButton4
            winwait, PhysX, License
            ControlClick, Button3
            ControlClick, Button4
            winwait, PhysX, successfully
            ControlClick, Button1
        }
        winwait, Darkness, Setup has finished
        if ( u > 0 ) {
            ControlClick, TNewListBoxButton1
            ControlClick, TNewButton4
        }
        winwaitclose, Darkness, Setup has finished
    "

    if w_workaround_wine_bug 23041
    then
        w_call d3dx9_36
    fi

    # you have to cd to the directory containing DarkLineage.exe before running it
    w_declare_exe "$W_PROGRAMS_X86_WIN\\Iceberg Interactive\\Darkness Within 2 Demo" "DarkLineage.exe"
}

#----------------------------------------------------------------

w_metadata dirt2_demo games \
    title="Dirt 2 Demo" \
    publisher="Codemasters" \
    year="2009" \
    media="download" \
    file1="Dirt2Demo.zip" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Codemasters/DiRT2 Demo/dirt2.exe"

load_dirt2_demo()
{
    w_download $W_PACKAGE "http://gamedaily.newaol.com/pub/Dirt2Demo.zip" 13af1beb8c4f6300e4655045b66aea1f8a29f2b3

    mkdir "$W_TMP/$W_PACKAGE"
    w_try_unzip -d "$W_TMP/$W_PACKAGE" "$W_CACHE/$W_PACKAGE/Dirt2Demo.zip"

    if w_workaround_wine_bug 23532
    then
       w_call gfw 
    fi

    if w_workaround_wine_bug 24868
    then
        w_call d3dx9_36
    fi

    cd "$W_TMP/$W_PACKAGE"

    w_ahk_do "
        Run, "Setup.exe"
        WinWait, Choose Setup Language, Select
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 500
            ControlClick Button1    ;next
            WinWait, DiRT2 Demo - InstallShield Wizard, Welcome
            sleep 500
            ControlClick Button1    ;next
            WinWait, DiRT2 Demo - InstallShield Wizard, License
            sleep 500
            ControlClick Button3    ;i accept
            sleep 500
            ControlClick Button1    ;next
            WinWait, DiRT2 Demo - InstallShield Wizard, Setup
            sleep 500
            ControlClick Button4    ;next
            WinWait, InstallShield Wizard, In order
            sleep 500
            ControlClick Button1    ;next
            WinWait, DiRT2 Demo - InstallShield Wizard, Ready
            sleep 500
            ControlClick Button1    ;next
        }
        WinWait, DiRT2 Demo - InstallShield Wizard, Complete
        if ( u > 0 ) {
            sleep 500
            ControlClick Button4    ;finish
        }
        WinWaitClose, DiRT2 Demo - InstallShield Wizard, Complete
        "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Codemasters\\DiRT2 Demo" "dirt2.exe"
}

#----------------------------------------------------------------

w_metadata divinity2_demo games \
    title="Divinity II Demo" \
    publisher="DTP Entertainment" \
    year="2010" \
    media="download" \
    file1="Divinity2_DEMO_EN.exe" \
    installed_file1="$W_PROGRAMS_X86_WIN/Divinity II - Ego Draconis - Demo/Bin/Divinity2_Demo.exe"

load_divinity2_demo()
{
    w_download $W_PACKAGE "http://demos.dtp-entertainment.ag/Divinity2_DEMO_EN.exe" \
        01161a1375f5ee3bb215753e40dd1dcdceffd3a7

    cd "$W_CACHE/$W_PACKAGE"

    w_ahk_do "
        Run, Divinity2_DEMO_EN.exe
        SetTitleMatchMode, 2
        WinWait,Setup - Divinity II - Ego Draconis - Demo
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Sleep 500
            ControlClick TNewButton1 ; Next
            WinWait,Setup - Divinity II - Ego Draconis - Demo, read
            Sleep 500
            ControlClick TNewRadioButton1 ;agreement
            Sleep 500
            ControlClick TNewButton2 ; Next
            WinWait,Setup - Divinity II - Ego Draconis - Demo, into
            Sleep 500
            ControlClick TNewButton3 ; Next
            WinWait,Setup - Divinity II - Ego Draconis - Demo, place
            Sleep 500
            ControlClick TNewButton4 ; Next
            WinWait,Setup - Divinity II - Ego Draconis - Demo, installation
            Sleep 500
            ControlClick TNewButton4 ; Install
            Loop
            {
                IfWinExist, NVIDIA PhysX Setup, must
                {
                    WinWait,NVIDIA PhysX Setup, must
                    Sleep 500
                    ControlClick Button3 ;accept
                    Sleep 500
                    ControlClick Button4 ; Next
                    WinWait,NVIDIA PhysX Setup, been
                    Sleep 500
                    ControlClick Button1 ; Finish
                }
                IfWinExist,Setup - Divinity II - Ego Draconis - Demo, launched
                {
                    break
                }
                Sleep 2000
            }
            WinWait,Setup - Divinity II - Ego Draconis - Demo, launched
            Sleep 500
            ControlFocus, TNewCheckListBox1, Desktop
            Sleep 500
            Send {Space}
            Sleep 500
            ControlClick TNewButton4 ; Finish
        }
        WinWaitClose
    "

    if w_workaround_wine_bug 24417
    then
        w_call d3dx9_36
    fi
    if w_workaround_wine_bug 25329
    then
        w_call wmp9
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Divinity II - Ego Draconis - Demo\\Bin" "Divinity2_Demo.exe"
}

#----------------------------------------------------------------

w_metadata dc2ba_demo games \
    title="Doras Carnival 2: Boardwalk Adventure Demo" \
    publisher="Nickelodeon" \
    year="2008" \
    media="download" \
    file1="InstallDorasCarnival2BoardwalkAdventure.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Shockwave.com/Dora's Carnival 2 - Boardwalk Adventure/Dora's Carnival 2 - Boardwalk Adventure.exe"

load_dc2ba_demo()
{
    # http://www.nickjr.com/games/p-doras-carnival-2-adventure.jhtml
    # b90fcca3837faafbd7ad0cd8f776976fbd146787 16 Sept 2010
    w_download $W_PACKAGE http://downloadcdn.shockwave.com/pub/doras-carnival-2-boardwalk-adventure/InstallDorasCarnival2BoardwalkAdventure.exe b90fcca3837faafbd7ad0cd8f776976fbd146787

    if w_workaround_wine_bug 23749
    then
        w_call ie6
    fi

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        SetTitleMatchMode, 2
        run InstallDorasCarnival2BoardwalkAdventure.exe
        winwait, Welcome
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            controlclick, Button1, Welcome
            sleep 1000
            winwait, End User License
            sleep 1000
            controlclick, Button1, End User License
            winwait, Choose Destination Location
            sleep 1000
            controlclick, Button1, Choose Destination Location
            winwait, FREE Toolbar
            sleep 1000
            controlclick, Button5, FREE Toolbar
            sleep 1000
            controlclick, Button1, FREE Toolbar
            winwait, Start Installation
            sleep 1000
            controlclick, Button1, Start Installation
        }
        winwait, Installation Complete
        if ( u > 0 ) {
            sleep 1000
            controlclick, Button1, Installation Complete
        }
        winwaitclose, Installation Complete
    "
    case "$OS" in
    "Windows_NT") ;;
    *) sleep 5
       killall winefile.exe
       ;;
    esac

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Shockwave.com\\Dora's Carnival 2 - Boardwalk Adventure" "Dora's Carnival 2 - Boardwalk Adventure.exe"

    if w_workaround_wine_bug 13496
    then
        w_call vcrun6
    fi
}

#----------------------------------------------------------------

w_metadata demolition_company_demo games \
    title="Demolition Company demo" \
    publisher="Giants Software" \
    year="2010" \
    media="manual_download" \
    file1="DemolitionCompanyDemoENv2.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Demolition Company Demo/DemolitionCompany.exe"

load_demolition_company_demo()
{
    w_download_manual $W_PACKAGE http://www.demolitioncompany-thegame.com/demo.php DemolitionCompanyDemoENv2.exe

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        SetTitleMatchMode, 2
        run, DemolitionCompanyDemoENv2.exe
        winwait, Setup - Demolition, This will install
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            controlclick, TNewButton1, Setup - Demolition, This will install
            winwait, Setup - Demolition, License Agreement
            sleep 1000
            controlclick, TNewRadioButton1, Setup - Demolition, License Agreement
            sleep 1000
            controlclick, TNewButton2, Setup - Demolition, License Agreement
            winwait, Setup - Demolition, Setup Type
            sleep 1000
            controlclick, TNewButton2, Setup - Demolition, Setup Type
            winwait, Setup - Demolition, Ready to Install
            sleep 1000
            controlclick, TNewButton2, Setup - Demolition, Ready to Install
            winwait, Setup - Demolition, Completing
            sleep 1000
            controlclick, TNewButton2, Setup - Demolition, Completing
        }
        winwaitclose, Setup - Demolition
    "
    w_declare_exe "$W_PROGRAMS_X86_WIN\\Demolition Company Demo\\" "DemolitionCompany.exe"
}

#----------------------------------------------------------------
 
w_metadata hegemonygold_demo games \
    title="Hegemony Gold beta 13" \
    publisher="Longbow Games" \
    year="2010" \
    media="download" \
    file1="HegemonyGoldInstaller.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Longbow Digital Arts/Hegemony Gold/Hegemony Gold.exe" \
    homepage="http://www.longbowgames.com/forums/topic/?id=2146" \
    rating="bronze"

load_hegemonygold_demo()
{
    if w_workaround_wine_bug 25767
    then
        w_warn "This game works, but has some rendering glitches in Wine."
    fi

    w_download hegemonygold_demo "http://www.longbowgames.com/downloads/Hegemony%20Gold%20Installer.exe" cb08360a732b2fb1d42d61f842dbedd0f0535a27 HegemonyGoldInstaller.exe

    cd "$W_CACHE/$W_PACKAGE"

    w_ahk_do "
        SetTitleMatchMode, 2
        Run, HegemonyGoldInstaller.exe
        WinWait,Hegemony
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Sleep 500
            ControlClick Button2 ; Next
            WinWait,Hegemony, License
            Sleep 500
            ControlClick Button2 ; Agree
            WinWait,Hegemony, Components
            Sleep 500
            Click, Left, 187, 185
            Sleep 500
            ControlClick Button2 ; Next
            WinWait,Hegemony, Location
            Sleep 500
            ControlClick Button2 ; Next
            WinWait,Hegemony, shortcuts
            Sleep 500
            ControlClick Button2 ; Install
            WinWait,Hegemony, Completing
            Sleep 500
            ControlFocus,Button4,launch
            Sleep 500
            Send {Space}
            Sleep 500
            ControlClick Button2 ; finish
        }
        WinWaitClose,Hegemony
    "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Longbow Digital Arts\\Hegemony Gold" "Hegemony Gold.exe"
}

#----------------------------------------------------------------

w_metadata hko games \
    title="Hello Kitty Online" \
    publisher="Sanrio Digital" \
    year="2009" \
    media="download" \
    file1="Hello Kitty Online Standard Installer.zip" \
    installed_exe1="$W_PROGRAMS_X86_WIN/SanrioTown/Hello Kitty Online/HKO.exe"

load_hko()
{
    w_download hko http://www.hellokittyonline.com/images/downloads/hkostandardinstaller.torrent fcbb6869551ba251a08402f6de81855e829407e9
    if ! test -f "$W_CACHE/hko/Hello Kitty Online Standard Installer.zip"
    then
        w_download_torrent hko hkostandardinstaller.torrent
    fi
    w_try_unzip "$W_CACHE/hko/Hello Kitty Online Standard Installer.zip" -d "$W_TMP"
    cd "$W_TMP/Hello Kitty Online Standard Installer"

    w_ahk_do "
        Run, setup.exe
        SetTitleMatchMode, 2
        WinWait,Setup - Hello Kitty Online, Welcome
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Sleep 500
            ControlClick TNewButton1 ; Next
            WinWait,Setup - Hello Kitty Online, License
            Sleep 500
            ControlFocus,TNewRadioButton1,Kitty
            Sleep 500
            Send {Space}
            Sleep 500
            ControlClick TNewButton2 ; Next
            WinWait,Setup - Hello Kitty Online, Location
            Sleep 500
            ControlClick TNewButton3 ; Next
            WinWait,Setup - Hello Kitty Online, Menu
            Sleep 500
            ControlClick TNewButton4 ; Next
            WinWait,Setup - Hello Kitty Online, Additional
            ControlFocus,TNewCheckListBox1,Kitty
            Sleep 500
            Send {Space}
            Sleep 500
            ControlClick TNewButton4 ; Next
            WinWait,Setup - Hello Kitty Online, now
            Sleep 500
            ControlClick TNewButton4 ; Install
        }
        WinWait,Setup - Hello Kitty Online, Completing
        if ( u > 0 ) {
            Sleep 500
            ControlClick TNewButton4 ; Finish
        }
        WinWaitClose
    "

    # Appdb says minigames need flash.  Very recent versions of wine
    # will offer to install flash on demand, just like windows.
    if test $W_OPT_UNATTENDED = 1
    then
        w_call flash
    fi

    if w_workaround_wine_bug 25132
    then
        w_call ie6
    fi
    if w_workaround_wine_bug 25133
    then
        w_call msxml3
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\SanrioTown\\Hello Kitty Online" "HKO.exe"
}

#----------------------------------------------------------------

w_metadata losthorizon_demo games \
    title="Lost Horizon Demo" \
    publisher="Deep Silver" \
    year="2010" \
    media="manual_download" \
    file1="Lost_Horizon_Demo_EN.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Deep Silver/Lost Horizon Demo/fsasgame.exe"

load_losthorizon_demo()
{
    w_download_manual $W_PACKAGE http://www.fileplanet.com/215704/download/Lost-Horizon-Demo Lost_Horizon_Demo_EN.exe

    cd "$W_CACHE/$W_PACKAGE"

    w_ahk_do "
        SetTitleMatchMode, 2
        run Lost_Horizon_Demo_EN.exe
        WinWait,Lost Horizon Demo, Destination
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Sleep 500
            Send {RAW}"$W_TMP"
            ControlClick Button2 ;Install
            WinWaitClose,Lost Horizon Demo,Installation
            Sleep 1000
            Click, Left, 169, 371
            WinWait,Lost Horizon Demo - InstallShield Wizard,Welcome
            Sleep 500
            ControlClick Button1 ;Next
            WinWait,Lost Horizon Demo - InstallShield Wizard,License
            ControlFocus,Button3,Lost Horizon Demo
            Sleep 500
            Send {Space}
            ControlClick Button1 ;Next
            WinWait,Lost Horizon Demo - InstallShield Wizard,program
            Sleep 500
            ControlClick Button2 ;Next
            WinWait,Lost Horizon Demo - InstallShield Wizard,features
            Sleep 500
            ControlClick Button4 ;Next
            WinWait,Lost Horizon Demo - InstallShield Wizard,begin
            Sleep 500
            ControlClick Button1 ;Next
        }
        WinWaitClose
        WinWait,Lost Horizon Demo - InstallShield Wizard,Complete
        if ( u > 0 ) {
            ControlFocus,Button2,Lost Horizon
            Sleep 500
            Send {Space}
            Sleep 500
            ControlClick Button4 ; Finish
        }
        WinWaitClose
    "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Deep Silver\\Lost Horizon Demo" "fsasgame.exe"
}

#----------------------------------------------------------------

w_metadata lswcs games \
    title="Lego Star Wars Complete Saga" \
    publisher="Lucasarts" \
    year="2009" \
    media="dvd" \
    file1="LEGOSAGA.iso"

load_lswcs()
{
    w_mount LEGOSAGA
    w_ahk_do "
        run ${W_ISO_MOUNT_LETTER}:setup.exe
        SetTitleMatchMode, 2
        winwait, Choose Setup Language
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            send {Enter}
            winwait, LEGO, License Agreement
            send a{Enter}
        }
        winwait, LEGO, method
        if ( u > 0 ) {
            ControlClick Easy Installation
            sleep 1000
        }
        winwaitclose, LEGO
    "
    # Installer crashes at end (http://bugs.winehq.org/show_bug.cgi?id=22529) but this doesn't seem to hurt.
    # Wait for all processes to exit, else unmount will fail
    #$W_WINESERVER -w

    w_declare_exe "$W_PROGRAMS_X86_WIN\\LucasArts\\LEGO Star Wars - The Complete Saga" "LEGOStarWarsSaga.exe"

    w_warn "This game is copy-protected, and requires the real disc in a real drive to run."
}

#----------------------------------------------------------------

w_metadata  lemonysnicket games \
   title="Lemony Snicket: A Series of Unfortunate Events" \
   publisher="Activision" \
   year="2004" \
   media="cd" \
   file1="Lemony Snicket.iso"

load_lemonysnicket()
{
    w_mount "Lemony Snicket"
    w_ahk_do "
        SetTitleMatchMode, 2
        Run, ${W_ISO_MOUNT_LETTER}:setup.exe
        WinWait, Lemony, Welcome
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            ControlClick, Button1 ; Next
            WinWait, Lemony, License
            sleep 1000
            ControlClick, Button2 ; Accept
            WinWait, Lemony, Minimum System
            sleep 1000
            ControlClick, Button2 ; Yes
            WinWait, Lemony, Destination
            sleep 1000
            ControlClick, Button1 ; Next
            WinWait, Lemony, Select Program Folder
            sleep 1000
            ControlClick, Button2 ; Next
            WinWait, Lemony, Start Copying
            sleep 1000
            ControlClick, Button1 ; Next
            WinWait, Question, Would you like to add a desktop shortcut
            sleep 1000
            ControlClick, Button2 ; No
            WinWait, Question, Would you like to register
            sleep 1000
            ControlClick, Button2 ; No
            ;WinWait, Information, Please register
            ;sleep 1000
            ;ControlClick, Button1 ; OK
            WinWait, Lemony, Complete
            sleep 1000
            ControlClick, Button4 ; Finish
            WinWait, Lemony, Play
            sleep 1000
            ControlClick, Button6 ; Exit
            WinWait, Lemony, Are you sure
            sleep 1000
            ControlClick, Button1 ; Yes already
        }
        WinWaitClose, Lemony
    "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Activision\\Lemony Snicket's A Series of Unfortunate Events" System\\game.exe
}

#----------------------------------------------------------------

w_metadata masseffect2 games \
    title="Mass Effect 2" \
    publisher="BioWare" \
    year="2010" \
    media="dvd" \
    file1="MassEffect2.iso" \
    file2="ME2_Disc2.iso"

load_masseffect2()
{
    w_mount MassEffect2
    w_read_key

    if w_workaround_wine_bug 22091
    then
        w_warn "Will probably hang at end of installer.  If a crash dialog comes up, you can kill it, it's done."
        w_call nocrashdialog
    fi

    if w_workaround_wine_bug 23126 "wine-1.3.[0-9]*"
    then
        w_call vcrun2005
    fi
    if w_workaround_wine_bug 23125 "wine-1.3.[0-9]*"
    then
        w_call d3dx10
    fi
    if w_workaround_wine_bug 23151
    then
        w_warn "Disabling glsl to workaround wine bug 23151. Users of nvidia cards will get weird effects without this. If you're on ATI/Intel, you can revert this with 'winetricks glsl-enable'"
        w_call glsl=disabled
    fi
    if w_workaround_wine_bug 22919
    then
        w_call physx
    fi

    w_ahk_do "
        SetTitleMatchMode, 2
        run, ${W_ISO_MOUNT_LETTER}:Setup.exe
        winwait, Installer Language
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            send {Enter}
            winwait, Mass Effect
            send {Enter}
            winwait, Mass Effect, License
            ControlClick, Button4
            ControlClick, Button2
            winwait, Mass Effect, Registration Code
            send $W_KEY
            ControlClick, Button2
            winwait, Mass Effect, Install Type
            ControlClick, Button2
        }
        winwait, Insert Disc
    "
    sleep 5
    w_mount ME2_Disc2
    w_ahk_do "
        SetTitleMatchMode, 2
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            winwait, Insert Disc
            ControlClick, Button4
            ; on windows, the first click doesn't seem to do it, so press enter, too
            sleep 1000
            send {Enter}
        }
        ; Some installs may not get to this point due to an installer hang/crash (bug 22919)
        ; The hang/crash happens after the Physx install but does not seem to affect gameplay
        loop
        {
            ifwinexist, Mass Effect, Finish
            {
                if ( u > 0 ) {
                    winkill, Mass Effect
                }
                break
            }
            Process, exist, Installer.exe
            me2pid = %ErrorLevel%
            if me2pid = 0
                break
            sleep 1000
        }
    "
    if w_workaround_wine_bug 6971
    then
        w_warn "See http://appdb.winehq.org/objectManager.php?sClass=version&iId=19125 for info on how to patch wine to work around bug 6971"
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Mass Effect 2\\Binaries" "MassEffect2.EXE"
}

#----------------------------------------------------------------

w_metadata maxmagicmarker_demo games \
    title="Max & the Magic Marker Demo" \
    publisher="Press Play" \
    year="2010" \
    media="download" \
    file1="max_demo_pc.zip" \
    installed_exe1="$W_PROGRAMS_X86_WIN/maxmagicmarker_demo/max and the magic markerdemo pc.exe"

load_maxmagicmarker_demo()
{
    w_download $W_PACKAGE http://www.maxandthemagicmarker.com/maxdemo/max_demo_pc.zip 1a79c583ff40e7b2cf05d18a89a806fd6b88a5d1

    w_try mkdir "$W_PROGRAMS_X86_UNIX"/$W_PACKAGE
    cd "$W_PROGRAMS_X86_UNIX"/$W_PACKAGE
    w_try_unzip "$W_CACHE/$W_PACKAGE"/max_demo_pc.zip
    # Work around bug in game?!
    mv "max and the magic markerdemo pc" "max and the magic markerdemo pc"_Data

    w_declare_exe "$W_PROGRAMS_X86_WIN\\$W_PACKAGE" "max and the magic markerdemo pc.exe"
}

#----------------------------------------------------------------

w_metadata menofwar games \
    title="Men of War" \
    publisher="Aspyr Media" \
    year="2009" \
    media="dvd" \
    file1="Men of War.iso" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Aspyr/Men of War/mow.exe"

load_menofwar()
{
    w_mount "Men of War"

    cd "$W_ISO_MOUNT_ROOT"
    w_ahk_do "
        SetTitleMatchMode, 2
        SetTitleMatchMode, slow
        run ${W_ISO_MOUNT_LETTER}:setup.exe
        winwait, Select Setup Language, Select the language
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            ControlClick, TNewButton1, Select Setup Language, Select the language
            winwait, Men of War
            sleep 1000
            ControlClick, TButton4, Men of War
            winwait, Setup - Men of War, ACCEPTANCE OF AGREEMENT
            sleep 1000
            ControlClick, TNewRadioButton1, Setup - Men of War, ACCEPTANCE OF AGREEMENT
            ControlClick, TNewButton1, Setup - Men of War, ACCEPTANCE OF AGREEMENT
        }
        winwait, Setup - Men of War, Setup has finished installing
        if ( u > 0 ) {
            sleep 1000
            ControlClick, x242 y254
            ControlClick, x242 y278
            ControlClick, TNewButton1, Setup - Men of War, Setup has finished
        }
    "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Aspyr\\Men of War" "mow.exe"
}

#----------------------------------------------------------------

w_metadata osmos_demo games \
    title="Osmos demo" \
    publisher="Hemisphere Games" \
    year="2009" \
    media="download" \
    file1="OsmosDemo_Installer_1.5.6.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/OsmosDemo/OsmosDemo.exe"

load_osmos_demo()
{
    w_download $W_PACKAGE http://gamedaily.newaol.com/pub/OsmosDemo_Installer_1.5.6.exe 7568f97100a73985a0fd625b63b205f4477578e8

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        SetTitleMatchMode, 2
        run OsmosDemo_Installer_1.5.6.exe
        winwait, Osmos, License
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            controlclick, Button2, Osmos Demo Setup, License Agreement
            winwait, Osmos Demo Setup, Choose Install Location
            sleep 500
            controlclick, Button2, Osmos Demo Setup, Choose Install Location
            winwait, Osmos Demo Setup, Choose Start Menu Folder
            sleep 500
            controlclick, Button2, Osmos Demo Setup, Choose Start Menu Folder
            winwait, Osmos Demo Setup, Installation Complete
            sleep 500
            controlclick, Button2, Osmos Demo Setup, Installation Complete
        }
        WinWaitClose
    "

    if w_workaround_wine_bug 24416
    then
        w_call vcrun2005
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\OsmosDemo" "OsmosDemo.exe"
}

#----------------------------------------------------------------

w_metadata plantsvszombies games \
    title="Plants vs. Zombies" \
    publisher="PopCap Games" \
    year="2009" \
    media="download" \
    file1="PlantsVsZombiesSetup.exe" \
    installed_file1="$W_PROGRAMS_X86_WIN/PopCap Games/Plants vs. Zombies/PlantsVsZombies.exe"

load_plantsvszombies()
{
    w_download $W_PACKAGE "http://downloads.popcap.com/www/popcap_downloads/PlantsVsZombiesSetup.exe" c46979be135ef1c486144fa062466cdc51b740f5

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        run PlantsVsZombiesSetup.exe
        winwait, Plants vs. Zombies Installer
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            send {Enter}
            winwait, Plants vs. Zombies License Agreement
            ControlClick Button1
        }
        winwait, Plants vs. Zombies Installation Complete!
        if ( u > 0 ) {
            sleep 1000
            send {Space}{Enter}
            ControlClick, x309 y278, Plants vs. Zombies Installation Complete!,,,, Pos
        }
        WinWaitClose
    "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\PopCap Games\\Plants vs. Zombies" "PlantsVsZombies.exe"
}

#----------------------------------------------------------------

w_metadata puzzleagent_demo games \
    title="Puzzle Agent Demo" \
    publisher="Telltale Games" \
    year="2010" \
    media="download" \
    file1="PuzzleAgent_PC_Setup.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Telltale Games/Puzzle Agent/Puzzle Agent/Grickle101.exe"

load_puzzleagent_demo()
{
    w_download $W_PACKAGE http://telltale.vo.llnwd.net/o15/games/puzzleagent/100/PuzzleAgent_PC_Setup.exe ac0012889fd80237928207c9d19b02f5968761a4

    cd "$W_CACHE/$W_PACKAGE"

    w_ahk_do "
        Run, PuzzleAgent_PC_Setup.exe
        SetTitleMatchMode, 2
        WinWait,Puzzle Agent Setup, Welcome
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Sleep 500
            ControlClick Button2 ; Next
            WinWait,Puzzle Agent Setup, properly
            Sleep 500
            ControlClick Button5 ;DirectX
            Sleep 500
            ControlClick Button2 ; Next
            WinWait,Puzzle Agent Setup, before
            Sleep 500
            ControlClick Button2 ; Agree
            WinWait,Puzzle Agent Setup, different
            Sleep 500
            ControlClick Button2 ; Install
            WinWait,Puzzle Agent Setup, your
            Sleep 500
            ControlClick Button4 ; Play
            Sleep 500
            ControlClick Button5 ; will
            Sleep 500
            ControlClick Button2 ; Finish
        }
        WinWaitClose, Puzzle Agent
    "

    if w_workaround_wine_bug 25210  # fixed in 1.3.8
    then
        w_call vcrun2008
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Telltale Games\\Puzzle Agent\\Puzzle Agent" "Grickle101.exe"
}

#----------------------------------------------------------------

w_metadata riseofnations_demo games \
    title="Rise of Nations Trial" \
    publisher="Microsoft" \
    year="2003" \
    media="manual_download" \
    file1="RiseOfNationsTrial.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Microsoft Games/Rise of Nations Trial/nations.exe"

load_riseofnations_demo()
{
    w_download_manual $W_PACKAGE http://download.cnet.com/Rise-of-Nations-Trial-Version/3000-7562_4-10730812.html RiseOfNationsTrial.exe 33cbf1ebc0a93cb840f6296d8b529f6155db95ee

    cd "$W_CACHE/$W_PACKAGE"

    w_ahk_do "
        SetTitleMatchMode, 2
        run RiseOfNationsTrial.exe
        WinWait,Rise Of Nations Trial Setup
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 2500
            ControlClick CButtonClassName2
            WinWait,Rise Of Nations Trial Setup, installed
            sleep 2500
            ControlClick CButtonClassName7
        }
        WinWaitClose
    "

    if w_workaround_wine_bug 9027
    then
        w_call directmusic
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Microsoft Games\\Rise of Nations Trial" "nations.exe"
}

#----------------------------------------------------------------

w_metadata theundergarden_demo games \
    title="The UnderGarden Demo" \
    publisher="Atari" \
    year="2010" \
    media="manual_download" \
    file1="TheUnderGarden_PC_B34_SRTB.30_28OCT10.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/The UnderGarden/TheUndergarden.exe"

load_theundergarden_demo()
{
    w_download_manual $W_PACKAGE http://www.bigdownload.com/games/the-undergarden/pc/the-undergarden-demo TheUnderGarden_PC_B34_SRTB.30_28OCT10.exe acf90c422ac2f2f242100f39bedfe7df0c95f7a

    if w_workaround_wine_bug 25384
    then
        w_call vcrun2008
    fi
    if w_workaround_wine_bug 25385
    then
        w_call d3dx9_36
    fi

    cd "$W_CACHE/$W_PACKAGE"

    w_ahk_do "
        SetTitleMatchMode, 2
        Run, TheUnderGarden_PC_B34_SRTB.30_28OCT10.exe
        WinWait,WinRAR
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Sleep 500
            ControlClick Button2 ; Install
            WinWait,Select Setup Language, during
            Sleep 500
            ControlClick TNewButton1 ;OK
            WinWait,Setup - The UnderGarden, your
            Sleep 500
            ControlClick TNewButton1 ;OK
            WinWait,Setup - The UnderGarden, License
            Sleep 500
            ControlClick TNewRadioButton1 ; accept
            Sleep 500
            ControlClick TNewButton2 ; Next
            WinWait,Setup - The UnderGarden, different
            Sleep 500
            ControlClick TNewButton3 ;Next
            WinWait,Setup - The UnderGarden, shortcuts
            Sleep 500
            ControlClick TNewButton4 ;OK
            WinWait,Setup - The UnderGarden, additional
            Sleep 500
            ControlFocus,TNewCheckListBox1,desktop
            Sleep 500
            Send {Space}
            Sleep 500
            ControlClick TNewButton4 ; Next
            WinWait,Setup - The UnderGarden, review
            Sleep 500
            ControlClick TNewButton4 ;Install
            WinWait,Microsoft Visual C, Visual
            Sleep 500
            ControlClick Button13 ;Cancel
            WinWait,Microsoft Visual C, want
            Sleep 500
            ControlClick Button1 ;Yes
            WinWait,Microsoft Visual C, chosen
            Sleep 500
            ControlClick Button2 ;Finish
            WinWait,Framework 3, Press
            Sleep 500
            ControlClick Button21 ;Cancel
            WinWait,Framework 3, want
            Sleep 500
            ControlClick Button1 ;Yes
            WinWait,Installing Microsoft, Runtime
            Sleep 500
            ControlClick Button6 ;Cancel
        }
        WinWait,Setup,launched
        if ( u > 0 ) {
            Sleep 500
            ControlClick TNewButton4 ;Finish
        }
        WinWaitClose,Setup,launched
    "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\The UnderGarden" "TheUndergarden.exe"
}

#----------------------------------------------------------------

w_metadata tmnationsforever games \
    title="TrackMania Nations Forever" \
    publisher="Nadeo" \
    year="2009" \
    media="download" \
    file1="tmnationsforever_setup.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/TmNationsForever/TmForever.exe"

load_tmnationsforever()
{
    if w_workaround_wine_bug 20915
    then
        w_warn "Gameplay and sound may be very choppy on some machines :-("
    fi

    w_download $W_PACKAGE "http://files.trackmaniaforever.com/tmnationsforever_setup.exe" cab0cf66db0471bc2674a3b1aebc35de0bca6ed0

    cd "$W_CACHE/$W_PACKAGE"

    w_ahk_do "
        SetTitleMatchMode, 2
        Run, tmnationsforever_setup.exe
        WinWait,Select Setup Language
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            Sleep 1000
            ControlClick TNewButton1 ; OK
            WinWait,Setup - TmNationsForever,Welcome
            Sleep 1000
            ControlClick TNewButton1 ; Next
            WinWait,Setup - TmNationsForever,License
            Sleep 1000
            ControlClick TNewRadioButton1 ; Accept
            Sleep 1000
            ControlClick TNewButton2 ; Next
            WinWait,Setup - TmNationsForever,Where
            Sleep 1000
            ControlClick TNewButton3 ; Next
            WinWait,Setup - TmNationsForever,shortcuts
            Sleep 1000
            ControlClick TNewButton4 ; Next
            WinWait,Setup - TmNationsForever,perform
            Sleep 1000
            ControlClick TNewButton4 ; Next
            WinWait,Setup - TmNationsForever,installing
            Sleep 1000
            ControlClick TNewButton4 ; Install
        }
        WinWait,Setup - TmNationsForever,finished
        if ( u > 0 ) {
            Sleep 1000
            ControlFocus, TNewCheckListBox1, TmNationsForever, finished
            Sleep 1000
            Send {Space} ; don't start game
            ControlClick TNewButton4 ; Finish
        }
        WinWaitClose
    "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\TmNationsForever" "TmForever.exe"
}

#----------------------------------------------------------------

w_metadata sammax304_demo games \
    title="Sam & Max 304: Beyond the Alley of the Dolls" \
    publisher="Telltale Games" \
    year="2010" \
    media="download" \
    file1="SamMax304_v02.18_unlockable_securom_pa_BigDownload.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Telltale Games/Sam and Max - The Devil's Playhouse/Beyond the Alley of the Dolls/SamMax304.exe"

load_sammax304_demo()
{
    if ! test -f "$W_CACHE/$W_PACKAGE"/SamMax304_v02.18_unlockable_securom_pa_BigDownload.exe
    then
        w_download $W_PACKAGE "http://gamedaily.newaol.com/pub/SamMax304_BigDownload.exe.zip" 5d3cefcf0c654d3646105e14cb3d06c61feb32f3
        cd "$W_CACHE/$W_PACKAGE"
        w_try_unzip SamMax304_BigDownload.exe.zip
        rm -f SamMax304_BigDownload.exe.zip
    fi

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        SetTitleMatchMode, 2
        Run, SamMax304_v02.18_unlockable_securom_pa_BigDownload.exe
        WinWait,Sam and Max Beyond the Alley of the Dolls Setup
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            ControlClick Button2 ; Next
            WinWait,Sam and Max Beyond the Alley of the Dolls Setup,DirectX
            ControlClick Button2 ; Next - Directx check defaulted
            WinWait,Sam and Max Beyond the Alley of the Dolls Setup,License
            ControlClick Button2 ; Agree
            WinWait,Sam and Max Beyond the Alley of the Dolls Setup,Location
            ControlClick Button2 ; Install
            WinWait,Sam and Max Beyond the Alley of the Dolls Setup,Finish
            ControlClick Button4 ; Uncheck Play Now
            ControlClick Button2 ; Finish
        }
        WinWaitClose
    "

    if w_workaround_wine_bug 24250
    then
        w_call vcrun2005
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Telltale Games\\Sam and Max - The Devil's Playhouse\\Beyond the Alley of the Dolls" "SamMax304.exe"
}

#----------------------------------------------------------------

w_metadata singularity games \
    title="Singularity" \
    publisher="Activision" \
    year="2010" \
    media="dvd" \
    file1="SNG_DVD.iso"

load_singularity()
{
    w_read_key
    w_mount SNG_DVD

    w_ahk_do "
        run ${W_ISO_MOUNT_LETTER}:setup.exe
        winwait, Activision(R) - InstallShield, Select the language for the installation from the choices below.
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            controlclick, Button1, Activision(R) - InstallShield, Select the language for the installation from the choices below.
            sleep 1000
            winwait, Singularity(TM), Keycode Check
            sleep 1000
            Send $W_KEY
            sleep 1000
            Send {Enter}
            ; Well this is annoying...
            Winwait, Keycode Check, The Keycode you entered appears to be valid.
            sleep 1000
            Send {Enter}
            winwait, Singularity(TM), The InstallShield Wizard will install Singularity(TM) on your computer
            sleep 1000
            controlclick, Button1, Singularity(TM), The InstallShield Wizard will install Singularity(TM) on your computer
            winwait, Singularity(TM), Please read the following license agreement carefully
            sleep 1000
            controlclick, Button5, Singularity(TM), Please read the following license agreement carefully
            sleep 1000
            controlclick, Button2, Singularity(TM), Please read the following license agreement carefully
            winwait, Singularity(TM), Minimum System Requirements
            sleep 1000
            controlclick, Button1, Singularity(TM), Minimum System Requirements
            winwait, Singularity(TM), Select the setup type to install
            controlclick, Button4, Singularity(TM), Select the setup type to install
        }
        ; Loop until installer window has been gone for at least two seconds
        Loop
        {
            sleep 1000
            IfWinExist, Singularity
                continue
            IfWinExist, Activision
                continue
            sleep 1000
            IfWinExist, Singularity
                continue
            IfWinExist, Activision
                continue
            break
        }
        "

    if w_workaround_wine_bug 6971
    then
        w_call mwo=force
    fi

    if w_workaround_wine_bug 22548
    then
        echo "Disabling \'depth of field\'"
        cat > "$W_TMP"/dof.reg <<_EOF_
REGEDIT4

[HKEY_CURRENT_USER\Software\Activision\Singularity]
"DepthOfField"=dword:00000000

_EOF_
        w_try_regedit "$W_TMP_WIN"\\dof.reg
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Activision\\Singularity(TM)\\Binaries" "Singularity.exe"

    # Clean up crap left over in c:\ when the installer runs the vc 2008 redistributable installer
    cd "$W_DRIVE_C"
    rm -f VC_RED.* eula.*.txt globdata.ini install.exe install.ini install.res.*.dll vcredist.bmp
}

#----------------------------------------------------------------

w_metadata stalker_pripyat_bench benchmarks \
    title="S.T.A.L.K.E.R Call of Pripyat benchmark" \
    publisher="GSC Game World" \
    year="2009" \
    media="manual_download" \
    file1="stkcop-bench-setup.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Call Of Pripyat Benchmark/Benchmark.exe"

load_stalker_pripyat_bench()
{
    # Much faster
    w_download_manual $W_PACKAGE http://www.bigdownload.com/games/stalker-call-of-pripyat/pc/stalker-call-of-pripyat-benchmark stkcop-bench-setup.exe 8691c3f289ecd0521bed60ffd46e65ad080206e0
    #w_download $W_PACKAGE http://files.gsc-game.com/st/bench/stkcop-bench-setup.exe 8691c3f289ecd0521bed60ffd46e65ad080206e0

    cd "$W_CACHE/$W_PACKAGE"

    # FIXME: a bit fragile, if you're browsing the web while installing, it sometimes gets stuck.
    w_ahk_do "
        SetTitleMatchMode, 2
        run stkcop-bench-setup.exe
        WinWait,Setup - Call Of Pripyat Benchmark
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            ControlClick TNewButton1 ; Next
            WinWait,Setup - Call Of Pripyat Benchmark,License
            sleep 1000
            ControlClick TNewRadioButton1 ; accept
            sleep 1000
            ControlClick TNewButton2 ; Next
            WinWait,Setup - Call Of Pripyat Benchmark,Destination
            sleep 1000
            ControlClick TNewButton3 ; Next
            WinWait,Setup - Call Of Pripyat Benchmark,shortcuts
            sleep 1000
            ControlClick TNewButton4 ; Next
            WinWait,Setup - Call Of Pripyat Benchmark,performed
            sleep 1000
            ControlClick TNewButton4 ; Next
            WinWait,Setup - Call Of Pripyat Benchmark,ready
            sleep 1000
            ControlClick, TNewButton4 ; Next  (nah, who reads doc?)
        }
        WinWait,Setup - Call Of Pripyat Benchmark,finished
        if ( u > 0 ) {
            sleep 1000
            Send {Space}  ; uncheck launch
            sleep 1000
            ControlClick TNewButton4 ; Finish
        }
        WinWaitClose,Setup - Call Of Pripyat Benchmark,finished
    "

    if w_workaround_wine_bug 24868
    then
        w_call d3dx9_31
        w_call d3dx9_42
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Call Of Pripyat Benchmark" "Benchmark.exe"
}

#----------------------------------------------------------------

w_metadata  torchlight games \
   title="Torchlight - boxed version" \
   publisher="Runic Games" \
   year="2009" \
   media="dvd" \
   file1="Torchlight.iso"

load_torchlight()
{
    w_mount "Torchlight"
    w_ahk_do "
        SetTitleMatchMode, 2
        Run, ${W_ISO_MOUNT_LETTER}:Torchlight.exe
        WinWait, Torchlight Setup, This wizard will guide
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            ControlClick, Button2, Torchlight Setup, This wizard will guide
            WinWait, Torchlight Setup, Please review the license terms
            sleep 1000
            ControlClick, Button2, Torchlight Setup, Please review the license terms
            WinWait, Torchlight Setup, Choose Install Location
            sleep 1000
            ControlClick, Button2, Torchlight Setup, Choose Install Location
            WinWait, Torchlight Setup, Installation Complete
            sleep 1000
            ControlClick, Button2, Torchlight Setup, Installation Complete
            WinWait, Torchlight Setup, Completing the Torchlight Setup Wizard
            sleep 1000
            ControlClick, Button4, Torchlight Setup, Completing the Torchlight Setup Wizard
            ControlClick, Button2, Torchlight Setup, Completing the Torchlight Setup Wizard
        }
        WinWaitClose, Torchlight Setup
    "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Runic Games\\Torchlight" Torchlight.exe
}

#----------------------------------------------------------------

w_metadata  twfc games \
    title="Transformers: War for Cybertron" \
    publisher="Activision" \
    year="2010" \
    media="dvd" \
    file1="TWFC_DVD.iso"

load_twfc()
{
    w_read_key
    w_mount TWFC_DVD

    w_ahk_do "
        run ${W_ISO_MOUNT_LETTER}:setup.exe
        SetTitleMatchMode, 2
        winwait, Activision, Select the language for the installation
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            controlclick, Button1, Activision, Select the language for the installation
            winwait, Transformers, Press NEXT to verify your key
            sleep 1000
            send $W_KEY
            send {Enter}
            winwait, Keycode Check, The Keycode you entered appears to be valid
            sleep 1000
            send {Enter}
            winwait, Transformers, The InstallShield Wizard will install Transformers
            sleep 1000
            controlclick, Button1, Transformers, The InstallShield Wizard will install Transformers
            winwait, Transformers, License Agreement
            sleep 1000
            controlclick, Button5, Transformers, License Agreement
            sleep 1000
            controlclick, Button2, Transformers, License Agreement
            winwait, Transformers, Minimum System Requirements
            sleep 1000
            controlclick, Button1, Transformers, Minimum System Requirements
            winwait, Transformers, Select the setup type to install
            sleep 1000
            controlclick, Button4, Transformers, Select the setup type to install
        }
        ; Installer exits silently. Prevent an early umount
        Loop
        {
            sleep 1000
            IfWinExist, Transformers
                continue
            IfWinExist, Activision
                continue
            sleep 1000
            IfWinExist, Transformers
                continue
            IfWinExist, Activision
                continue
            break
        }
    "

    if w_workaround_wine_bug 6971
    then
        w_call mwo=force
    fi

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Activision\\Transformers - War for Cybertron\\Binaries" "TWFC.exe"

    # Clean up crap left over in c:\ when the installer runs the vc 2008 redistributable installer
    cd "$W_DRIVE_C"
    rm -f VC_RED.* eula.*.txt globdata.ini install.exe install.ini install.res.*.dll vcredist.bmp
}

#----------------------------------------------------------------

w_metadata ut3 games \
    title="Unreal Tournament 3" \
    publisher="Midway Games" \
    year="2007" \
    media="dvd" \
    file1="UT3_RC7.iso" \
    file2="UT3Patch5.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Unreal Tournament 3/Binaries/UT3.exe"

load_ut3()
{
    w_download_manual $W_PACKAGE "http://www.filefront.com/13709855/UT3Patch5.exe" UT3Patch5.exe
    w_try w_mount UT3_RC7

    w_ahk_do "
        run ${W_ISO_MOUNT_LETTER}:SetupUT3.exe
        SetTitleMatchMode, 2
        WinWait, Choose Setup Language
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 500
            ControlClick Button1   ; OK
            WinWait, Unreal Tournament 3, GAMESPY ; License Agreement
            sleep 500
            ControlClick Button2   ; Yes
            WinWait, Unreal Tournament 3, UnrealEd ; License Agreement
            sleep 500
            ControlClick Button2   ; Yes
            WinWait, , Choose Destination
            sleep 500
            ControlClick Button1   ; Next
            WinWait, AGEIA PhysX v7.09.13
            sleep 500
            ControlClick Button3   ; Accept
            ControlClick Button4   ; Next
            WinWait, AGEIA PhysX v7.09.13, Finish
            sleep 500
            ControlClick Button1   ; Finish
            ; game now begins installing
        }
        WinWait, , InstallShield Wizard Complete
        if ( u > 0 ) {
            sleep 500
            ControlClick Button4   ; Finish
        }
        WinWaitClose
    "

    cd "$W_CACHE/$W_PACKAGE"
  
    w_ahk_do "
        SetTitleMatchMode, 2
        run UT3Patch5.exe
        WinWait, License
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 500
            ControlClick Button1   ; Accept
            WinWait, End User License Agreement
            sleep 500
            ControlClick Button1   ; Accept
            WinWait, Patch UT3
            sleep 500
            ControlClick Button1   ; Yes
        }
        WinWait, , UT3 was successfully patched!
        if ( u > 0 ) {
            sleep 500
            ControlClick Button1   ; OK
        }
        WinWaitClose
    "

    if w_workaround_wine_bug 6971
    then
        w_call mwo=force
        w_warn "Mouse will be disabled in in-game menu. Must use keyboard to navigate.  Alternately, patch wine as described in bug 6971 to use xinput2."
    fi

    # FIXME: enter user's key if -q
    w_declare_exe "$W_PROGRAMS_X86_WIN\\Unreal Tournament 3\\Binaries" "UT3.exe"
}

#----------------------------------------------------------------

w_metadata  wog games \
    title="World of Goo Demo" \
    publisher="2D Boy" \
    year="2008" \
    media="download" \
    file1="WorldOfGooDemo.1.0.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/WorldOfGooDemo/WorldOfGoo.exe"

load_wog()
{
    if ! test -f "$W_CACHE/wog/WorldOfGooDemo.1.0.exe"
    then
        # Get temporary download location
        w_download wog "http://www.worldofgoo.com/dl2.php?lk=demo&filename=WorldOfGooDemo.1.0.exe"
        URL=`cat "$W_CACHE/wog/dl2.php?lk=demo&filename=WorldOfGooDemo.1.0.exe" |
           grep WorldOfGooDemo.1.0.exe | sed 's,.*http,http,;s,".*,,'`
        rm "$W_CACHE/wog/dl2.php?lk=demo&filename=WorldOfGooDemo.1.0.exe"

        w_download wog "$URL" e61d8253b9fe0663cb3c69018bb3d2ec6152d488
    fi

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        run WorldOfGooDemo.1.0.exe
        winwait, World of Goo Setup, License Agreement
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            WinActivate
            send {Enter}
            winwait, World of Goo Setup, Choose Components
            send {Enter}
            winwait, World of Goo Setup, Choose Install Location
            send {Enter}
            winwait, World of Goo Setup, Thank you
            ControlClick, Make me dirty right now, World of Goo Setup, Thank you
            send {Enter}
        }
        winwaitclose, World of Goo Setup
        "
    w_declare_exe "$W_PROGRAMS_X86_WIN\\WorldOfGooDemo" WorldOfGoo.exe
}

#----------------------------------------------------------------

w_metadata zootycoon2_demo games \
    title="Zoo Tycoon 2 demo" \
    publisher="Microsoft" \
    year="2004" \
    media="download" \
    file1="Zoo2Trial.exe" \
    installed_exe1="$W_PROGRAMS_X86_WIN/Microsoft Games/Zoo Tycoon 2 Trial Version/zt2demoretail.exe"

load_zootycoon2_demo()
{
    w_download $W_PACKAGE "http://download.microsoft.com/download/9/f/6/9f6a95f0-f34a-4312-9749-77b81d3de245/Zoo2Trial.exe" 60ad1bb34351f97b579c58234b926055f7979126

    cd "$W_CACHE/$W_PACKAGE"
    w_ahk_do "
        ; Uses winwaitactive, because the windows appear and immediately after another window
        ; gets in the way, then disappears after a second or so
        SetTitleMatchMode, 2
        run Zoo2Trial.exe
        winwaitclose, APPMESSAGE
        winwaitactive, Zoo Tycoon 2 Trial, AUTORUN
        u = $W_OPT_UNATTENDED
        if ( u > 0 ) {
            sleep 1000
            controlclick, CButtonClassName1, Zoo Tycoon 2 Trial, AUTORUN
            winwaitclose, APPMESSAGE
            winwaitactive, Zoo Tycoon 2 Trial, INSTALLTYPE
            ; 1 second was not enough.
            sleep 3000
            controlclick, CButtonClassName1, Zoo Tycoon 2 Trial, INSTALLTYPE
        }
        winwaitactive, Zoo Tycoon 2 Trial, COMPLETE
        winclose, Zoo Tycoon 2 Trial, COMPLETE
        "

    w_declare_exe "$W_PROGRAMS_X86_WIN\\Microsoft Games\\Zoo Tycoon 2 Trial Version" "zt2demoretail.exe"
}

#----------------------------------------------------------------
# Settings
#----------------------------------------------------------------
# DirectSound settings

w_metadata dsoundbug9612 settings \
    title="Use DirectSound MaxShadowSize=0 workaround for wine bug 9612"

load_dsoundbug9612()
{
    if w_workaround_wine_bug 9612
    then
        echo "Enabling DirectSound workaround for bug #9612"
        cat > "$W_TMP"/dsoundmaxshadow.reg <<_EOF_
REGEDIT4

[HKEY_CURRENT_USER\Software\Wine\DirectSound]
"MaxShadowSize"="0"

_EOF_
        w_try_regedit "$W_TMP_WIN"\\dsoundmaxshadow.reg
    fi
}

#----------------------------------------------------------------
# Direct3D settings

winetricks_set_wined3d_var()
{
    # Filter out/correct bad or partial values
    # Confusing because dinput uses 'disable', but d3d uses 'disabled'
    # see wined3d_dll_init() in dlls/wined3d/wined3d_main.c
    # and DllMain() in dlls/ddraw/main.c
    case $2 in
    disable*) arg=disabled;;
    enable*) arg=enabled;;
    hard*) arg=hardware;;
    repack) arg=repack;;
    backbuffer|fbo|gdi|none|opengl|readdraw|readtex|texdraw|textex|auto) arg=$2;;
    [0-9]*) arg=$2;;
    *) w_die "illegal value $2 for $1";;
    esac

    echo "Setting Direct3D/$1 to $2"
    cat > "$W_TMP"/set-wined3d.reg <<_EOF_
REGEDIT4

[HKEY_CURRENT_USER\Software\Wine\Direct3D]
"$1"="$2"

_EOF_
    w_try_regedit "$W_TMP_WIN"\\set-wined3d.reg
}

#----------------------------------------------------------------

w_metadata glsl=enabled settings \
    title="Enable glsl shaders (default)"
w_metadata glsl=disabled settings \
    title="Disable glsl shaders, use arb shaders (faster, but sometimes breaks)"

load_glsl()
{
    winetricks_set_wined3d_var UseGLSL $1
}

#----------------------------------------------------------------

w_metadata multisampling=enabled settings \
    title="Enable Direct3D multisampling"
w_metadata multisampling=disabled settings \
    title="Disable Direct3D multisampling"

load_multisampling()
{
    winetricks_set_wined3d_var Multisampling $1
}

#----------------------------------------------------------------

w_metadata npm=repack settings \
    title="Set NonPower2Mode to repack"

load_npm()
{
    winetricks_set_wined3d_var NonPower2Mode $1
}

#----------------------------------------------------------------
 
w_metadata orm=fbo settings \
    title="Set OffscreenRenderingMode=fbo (default)"
w_metadata orm=backbuffer settings \
    title="Set OffscreenRenderingMode=backbuffer"

load_orm()
{
    winetricks_set_wined3d_var OffscreenRenderingMode $1
}

#----------------------------------------------------------------

w_metadata psm=enabled settings \
    title="Set PixelShaderMode to enabled"
w_metadata psm=disabled settings \
    title="Set PixelShaderMode to disabled"

load_psm()
{
    winetricks_set_wined3d_var PixelShaderMode $1
}

#----------------------------------------------------------------

w_metadata strictdrawordering=enabled settings \
    title="Enable StrictDrawOrdering (default)"
w_metadata strictdrawordering=disabled settings \
    title="Disable StrictDrawOrdering"

load_strictdrawordering()
{
    winetricks_set_wined3d_var StrictDrawOrdering $1
}

#----------------------------------------------------------------

w_metadata rtlm=auto settings \
    title="Set RenderTargetLockMode to auto (default)"
w_metadata rtlm=disabled settings \
    title="Set RenderTargetLockMode to disabled"
w_metadata rtlm=readdraw settings \
    title="Set RenderTargetLockMode to readdraw"
w_metadata rtlm=readtex settings \
    title="Set RenderTargetLockMode to readtex"
w_metadata rtlm=texdraw settings \
    title="Set RenderTargetLockMode to texdraw"
w_metadata rtlm=textex settings \
    title="Set RenderTargetLockMode to textex"

load_rtlm()
{
    winetricks_set_wined3d_var RenderTargetLockMode $1
}

#----------------------------------------------------------------
# DirectDraw settings

w_metadata ddr=gdi settings \
    title="Set DirectDrawRenderer to gdi"
w_metadata ddr=opengl settings \
    title="Set DirectDrawRenderer to opengl"

load_ddr()
{
    winetricks_set_wined3d_var DirectDrawRenderer $1
}

#----------------------------------------------------------------
# DirectInput settings

w_metadata mwo=force settings \
    title="Set DirectInput MouseWarpOverride to force (needed by some games)"
w_metadata mwo=enabled settings \
    title="Set DirectInput MouseWarpOverride to enabled (default)"
w_metadata mwo=disable settings \
    title="Set DirectInput MouseWarpOverride to disable"

load_mwo()
{
    # Filter out/correct bad or partial values
    # Confusing because dinput uses 'disable', but d3d uses 'disabled'
    # see alloc_device() in dlls/dinput/mouse.c
    case $1 in
    enable*) arg=enabled;;
    disable*) arg=disable;;
    force) arg=force;;
    *) w_die "illegal value $1 for MouseWarpOverride";;
    esac

    echo "Setting MouseWarpOverride to $arg"
    cat > "$W_TMP"/set-mwo.reg <<_EOF_
REGEDIT4

[HKEY_CURRENT_USER\Software\Wine\DirectInput]
"MouseWarpOverride"="$1"

_EOF_
    w_try_regedit "$W_TMP"/set-mwo.reg
}

#----------------------------------------------------------------
# Other settings

#----------------------------------------------------------------

w_metadata alldlls=default settings \
    title="Remove all DLL overrides"
w_metadata alldlls=builtin settings \
    title="Override most common DLLs to builtin (except msvcp90 and d3d9x_xx)"

load_alldlls()
{
    case $1 in
    default) w_override_no_dlls ;;
    builtin) w_override_all_dlls ;;
    esac
}

w_metadata fontsmooth=disable settings \
    title="Disable font smoothing"
w_metadata fontsmooth=bgr settings \
    title="Enable subpixel font smoothing for BGR LCDs"
w_metadata fontsmooth=rgb settings \
    title="Enable subpixel font smoothing for RGB LCDs"
w_metadata fontsmooth=gray settings \
    title="Enable subpixel font smoothing"

load_fontsmooth()
{
    case $1 in
    disable)   FontSmoothing=0; FontSmoothingOrientation=1; FontSmoothingType=0;;
    gray|grey) FontSmoothing=2; FontSmoothingOrientation=1; FontSmoothingType=1;;
    bgr)       FontSmoothing=2; FontSmoothingOrientation=0; FontSmoothingType=2;;
    rgb)       FontSmoothing=2; FontSmoothingOrientation=1; FontSmoothingType=2;;
    *) w_die "unknown font smoothing type $1";;
    esac

    echo "Setting font smoothing to $1"

    cat > "$W_TMP"/fontsmooth.reg <<_EOF_
REGEDIT4

[HKEY_CURRENT_USER\Control Panel\Desktop]
"FontSmoothing"="0"
"FontSmoothingGamma"=dword:00000578
"FontSmoothingOrientation"=dword:00000001
"FontSmoothingType"=dword:00000000

_EOF_
    w_try_regedit "$W_TMP_WIN"\\fontsmooth.reg
}

#----------------------------------------------------------------

w_metadata forcemono settings \
    title="Force using mono instead of .Net (for debugging)"

load_forcemono()
{
    w_override_dlls native mscoree.dll
    w_override_dlls disabled mscorsvw.exe
}

#----------------------------------------------------------------

w_metadata heapcheck settings \
    title="Enable heap checking with GlobalFlag"

load_heapcheck()
{
    cat > "$W_TMP"/heapcheck.reg <<_EOF_
REGEDIT4

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager]
"GlobalFlag"=dword:00200030

_EOF_
    w_try_regedit "$W_TMP_WIN"\\heapcheck.reg
}

#----------------------------------------------------------------

w_metadata hosts settings \
    title="Add empty C:\windows\system32\drivers\etc\{hosts,services} files"

load_hosts()
{
    # Create fake system32\drivers\etc\hosts and system32\drivers\etc\services files.
    # The hosts file is used to map network names to IP addresses without DNS.
    # The services file is used map service names to network ports.
    # Some apps depend on these files, but they're not implemented in wine.
    # Fortunately, empty files in the correct location satisfy those apps.
    # See http://bugs.winehq.org/show_bug.cgi?id=12076

    # It's in system32 for both win32/win64
    mkdir -p "$W_WINDIR_UNIX"/system32/drivers/etc
    touch "$W_WINDIR_UNIX"/system32/drivers/etc/hosts
    touch "$W_WINDIR_UNIX"/system32/drivers/etc/services
}

#----------------------------------------------------------------

w_metadata native_mdac settings \
    title="Override odbc32, odbccp32 and oledb32"

load_native_mdac()
{
    # Set those overrides globally so user programs get MDAC's odbc
    # instead of wine's unixodbc
    w_override_dlls native,builtin odbc32 odbccp32 oledb32
}

#----------------------------------------------------------------

w_metadata native_oleaut32 settings \
    title="Override oleaut32"

load_native_oleaut32()
{
    w_override_dlls native,builtin oleaut32
}

#----------------------------------------------------------------

w_metadata nocrashdialog settings \
    title="Disable crash dialog"

load_nocrashdialog()
{
    echo "Disabling graphical crash dialog"
    cat > "$W_TMP"/crashdialog.reg <<_EOF_
REGEDIT4

[HKEY_CURRENT_USER\Software\Wine\WineDbg]
"ShowCrashDialog"=dword:00000000

_EOF_
    cd "$W_TMP"
    w_try_regedit crashdialog.reg
}

#----------------------------------------------------------------

w_metadata nt40 settings \
    title="Set windows version to Windows NT 4.0"

load_nt40()
{
    w_set_winver nt40
}

#----------------------------------------------------------------

w_metadata sandbox settings \
    title="Sandbox the wineprefix - remove links to HOME"

load_sandbox()
{
    w_skip_windows sandbox && return

    # Unmap drive Z
    # Might want to unpack gecko first, since Wine won't be able to get to /usr/lib/wine after this
    rm -f "$WINEPREFIX/dosdevices/z:"

    # FIXME: these are language-specific, we probably need to localize these
    # remove symlinks (won't do anything if they're already directories)
    rm -f "$WINEPREFIX/drive_c/users/$USER/Desktop"
    rm -f "$WINEPREFIX/drive_c/users/$USER/My Documents"
    rm -f "$WINEPREFIX/drive_c/users/$USER/My Music"
    rm -f "$WINEPREFIX/drive_c/users/$USER/My Pictures"
    rm -f "$WINEPREFIX/drive_c/users/$USER/My Videos"
    # create replacement directories if needed
    mkdir -p "$WINEPREFIX/drive_c/users/$USER/Desktop"
    mkdir -p "$WINEPREFIX/drive_c/users/$USER/My Documents"
    mkdir -p "$WINEPREFIX/drive_c/users/$USER/My Music"
    mkdir -p "$WINEPREFIX/drive_c/users/$USER/My Pictures"
    mkdir -p "$WINEPREFIX/drive_c/users/$USER/My Videos"

    # Disable unixfs
    # Unfortunately, when you run with a different version of wine, wine will recreate this key.
    # See http://bugs.winehq.org/show_bug.cgi?id=22450
    $WINE regedit /d 'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\Namespace\{9D20AAE8-0625-44B0-9CA7-71889C2254D9}'

    # Disable recreation of the above key - or any updating of the regisry - when running with new version of wine.
    echo disable > "$WINEPREFIX/.update-timestamp"
}

#----------------------------------------------------------------

w_metadata sound=alsa settings \
    title="Set sound driver to ALSA"
w_metadata sound=coreaudio settings \
    title="Set sound driver to Mac CoreAudio"
w_metadata sound=disabled settings \
    title="Set sound driver to disabled"
w_metadata sound=esd settings \
    title="Set sound driver to esound"
w_metadata sound=jack settings \
    title="Set sound driver to Jack"
w_metadata sound=nas settings \
    title="Set sound driver to NAS"
w_metadata sound=oss settings \
    title="Set sound driver to OSS"

load_sound()
{
    echo "Setting sound driver to $1"
    cat > "$W_TMP"/set-sound.reg <<_EOF_
REGEDIT4

[HKEY_CURRENT_USER\Software\Wine\Drivers]
"Audio"="$1"

_EOF_
    w_try_regedit "$W_TMP_WIN"\\set-sound.reg
}

#----------------------------------------------------------------

w_metadata vd=off settings \
    title="Disable virtual desktop"
w_metadata vd=800x600 settings \
    title="Enable virtual desktop, set size to 800x600"
w_metadata vd=1024x768 settings \
    title="Enable virtual desktop, set size to 1024x768"
w_metadata vd=1280x1024 settings \
    title="Enable virtual desktop, set size to 1280x1024"
w_metadata vd=1440x900 settings \
    title="Enable virtual desktop, set size to 1440x900"

load_vd()
{
    size=$1
    case $size in
    off|disabled)
        cat > "$W_TMP"/vd.reg <<_EOF_
REGEDIT4

[HKEY_CURRENT_USER\Software\Wine\Explorer]
"Desktop"=-
[HKEY_CURRENT_USER\Software\Wine\Explorer\Desktops]
"Default"=-

_EOF_
        ;;
    [1-9]*x[1-9]*)
        cat > "$W_TMP"/vd.reg <<_EOF_
REGEDIT4

[HKEY_CURRENT_USER\Software\Wine\Explorer]
"Desktop"="Default"
[HKEY_CURRENT_USER\Software\Wine\Explorer\Desktops]
"Default"="$size"

_EOF_
        ;;
    *)
        w_die "you want a virtual desktop of $size?  I don't understand."
        ;;
    esac
    w_try_regedit "$W_TMP_WIN"/vd.reg
}

#----------------------------------------------------------------

w_metadata vista settings \
    title="Set windows version to Windows Vista"

load_vista()
{
    w_set_winver vista
}

#----------------------------------------------------------------

w_metadata volnum settings \
    title="Rename drive_c to harddiskvolume0 (needed by some installers)"

load_volnum() {
    w_skip_windows "volnum" && return

    # Recent Microsoft installers are often based on "windows package manager", see
    # http://support.microsoft.com/kb/262841 and
    # http://www.microsoft.com/technet/prodtechnol/windowsserver2003/deployment/winupdte.mspx
    # These installers check the drive name, and if it doesn't start with 'harddisk',
    # they complain "Unable to find a volume for file extraction", see
    # http://bugs.winehq.org/show_bug.cgi?id=5351
    # You may be able to work around this by using the installer's /x or /extract switch,
    # but renaming drive_c to "harddiskvolume0" lets you just run the installer as normal.

    if test ! -d "$WINEPREFIX"/harddiskvolume0/
    then
        ln -s drive_c "$WINEPREFIX"/harddiskvolume0
        rm "$WINEPREFIX"/dosdevices/c:
        ln -s ../harddiskvolume0 "$WINEPREFIX"/dosdevices/c:
        echo "Renamed drive_c to harddiskvolume0"
    else
        echo "drive_c already named harddiskvolume0"
    fi
}

#----------------------------------------------------------------

w_metadata vsm=hardware settings \
    title="Set VertexShaderMode to hardware"

load_vsm()
{
    winetricks_set_wined3d_var VertexShaders $1
}

#----------------------------------------------------------------

w_metadata win2k settings \
    title="Set windows version to Windows 2000"

load_win2k()
{
    w_set_winver win2k
}

#----------------------------------------------------------------

w_metadata win31 settings \
    title="Set windows version to Windows 3.1"

load_win31()
{
    w_set_winver win31
}

#----------------------------------------------------------------

w_metadata win7 settings \
    title="Set windows version to Windows 7"

load_win7()
{
    w_set_winver win7
}

#----------------------------------------------------------------

w_metadata win98 settings \
    title="Set windows version to Windows 98"

load_win98()
{
    w_set_winver win98
}

#----------------------------------------------------------------

# Really, we should support other values, since winetricks did
w_metadata winver= settings \
    title="Set windows version to default (winxp)"

load_winver()
{
    w_set_winver winxp
}

#----------------------------------------------------------------

w_metadata winxp settings \
    title="Set windows version to Windows XP"

load_winxp()
{
    w_set_winver winxp
}

#----------------------------------------------------------------

#---- Main Program ----

winetricks_stats_init()
{
    # Load opt-in status if not already set by a commandline option
    if test ! "$WINETRICKS_STATS_REPORT" && test -f $W_CACHE/track_usage
    then
        WINETRICKS_STATS_REPORT=`cat $W_CACHE/track_usage`
    fi

    if test ! "$WINETRICKS_STATS_REPORT" 
    then
        # No opt-in status found.  If GUI active, ask user whether they would like to opt in.
        case $WINETRICKS_GUI in
        zenity) 
            case $LANG in
            *)
                title="One-time question about helping Winetricks development"
                question="Would you like to help winetricks development by letting winetricks report statistics?  You can turn reporting off at any time with the command 'winetricks --optout'"
                thanks="Thanks!  You won't be asked this question again.  Remember, you can turn reporting off at any time with the command 'winetricks --optout'"
                declined="OK, winetricks will *not* report statistics.  You won't be asked this question again."
                ;;
            esac
            if zenity --question --text "$question" --title "$title"
            then
                zenity --info --text "$thanks"
                WINETRICKS_STATS_REPORT=1
            else
                zenity --info --text "$declined"
                WINETRICKS_STATS_REPORT=0
            fi
            echo $WINETRICKS_STATS_REPORT > $W_CACHE/track_usage
            ;;
        esac
    fi

    # Save opt-in status
    if test "$WINETRICKS_STATS_REPORT"
    then
        echo "$WINETRICKS_STATS_REPORT" > $W_CACHE/track_usage
    fi
}

# Retrieve a short string with the operating system name and version
winetricks_os_description()
{
    (
    case "$OS" in
    "Windows_NT")
        echo windows ;;
    *)  SW_VERS=`which sw_vers 2>/dev/null``
        LSB_RELEASE=`which lsb_release 2>/dev/null``
        if test -x "$SW_VERS"
        then
            # Mac
            $SW_VERS -productName; $SW_VERS -productVersion
        elif test -x "$LSB_RELEASE"
        then
            # Linux
            $LSB_RELEASE -d | sed 's/Description: *//'
        elif test -f /etc/gentoo-release
        then
            cat /etc/gentoo-release
        else
            echo "unknown"
        fi
        ;;
    esac 
    ) | tr '\012' ' '
}

winetricks_stats_report()
{
    # If and only if user has opted in to usage tracking, report the usage.
    case "$WINETRICKS_STATS_REPORT" in
    1) ;;
    *) return;;
    esac

    echo "You opted in, so reporting '$WINETRICKS_STATS_BREADCRUMBS' to the winetricks maintainer so he knows which winetricks verbs get used and which don't.  Use --optout to disable future reports."

    report="os=`winetricks_os_description`&winetricks=$WINETRICKS_VERSION&breadcrumbs=$WINETRICKS_STATS_BREADCRUMBS"
    # Just do a HEAD request with the raw commandline.  
    # Yes, this can be fooled by caches.  That's ok.
    if [ -x "`which wget 2>/dev/null`" ]
    then
        wget --spider "http://kegel.com/data/winetricks-usage?$report" > /dev/null 2>&1 || true
    elif [ -x "`which curl 2>/dev/null`" ]
    then
        curl -I "http://kegel.com/data/winetricks-usage?$report" > /dev/null 2>&1 || true
    fi
}

# Do whatever the current menu says to the given app
# Unless you're in the run or uninstall menus, that means to install it.
winetricks_do_app()
{
    case $WINETRICKS_CURMENU in
    run)
        winetricks_run_app $1
        ;;
    uninstall)
        winetricks_uninstall_app $1
        ;;
    *)
        winetricks_install_app $1
        ;;
    esac
}

# Usage: execute_command verb[=argument]
execute_command()
{
    # log what we execute for possible later statistics reporting
    WINETRICKS_STATS_BREADCRUMBS="$WINETRICKS_STATS_BREADCRUMBS $*"

    case $1 in
    *=*) arg=`echo $1 | sed 's/.*=//'`; cmd=`echo $1 | sed 's/=.*//'`;;
    *) cmd=$1; arg="" ;;
    esac

    case $1 in

    # FIXME: avoid duplicated code
    apps|benchmarks|dlls|fonts|games|run|uninstall|settings)
        WINETRICKS_CURMENU=$1
        ;;

    # Late options
    -*)
        if ! winetricks_handle_option $1
        then
            winetricks_usage
            exit 1
        fi
        ;;

    # Hard-coded verbs
    list) winetricks_list_all ;;
    list-cached) winetricks_list_cached ;;
    list-download) winetricks_list_download ;;
    list-manual-download) winetricks_list_manual_download ;;
    list-installed) winetricks_list_installed ;;
    unattended) winetricks_set_unattended 1 ;;
    attended) winetricks_set_unattended 0 ;;

    # Use winecfg if you want a gui for plain old dll overrides
    gameux=*|mmdevapi=*|oleaut32=*) w_override_dlls $arg $cmd;;

    # Hacks for backwards compatibility
    cc580) winetricks_do_app comctl32 ;;
    comdlg32.ocx) winetricks_do_app comdlg32ocx ;;
    dotnet1) winetricks_do_app dotnet11 ;;
    dotnet2) winetricks_do_app dotnet20 ;;
    fm20) winetricks_do_app controlpad ;;   # art2kmin also comes with fm20.dll
    fontsmooth-bgr) winetricks_do_app fontsmooth=bgr ;;
    fontsmooth-disable) winetricks_do_app fontsmooth=disable ;;
    fontsmooth-gray) winetricks_do_app fontsmooth=gray ;;
    fontsmooth-rgb) winetricks_do_app fontsmooth=rgb ;;
    glsl-disable) winetricks_do_app glsl=disabled ;;
    glsl-enable) winetricks_do_app glsl=enabled ;;
    ie6_full) winetricks_do_app ie6 ;;
    jscript) winetricks_do_app wsh56js ;;            # FIXME: use wsh57 instead?
    mwo=disabled) winetricks_do_app mwo=disable ;;   # FIXME: relax matching so we can handle these spelling differences in verb instead of here
    npm-repack) winetricks_do_app npm=repack ;;
    oss) winetricks_do_app sound=oss ;;
    psm=off) winetricks_do_app psm=disabled ;;
    psm=on) winetricks_do_app psm=enabled ;;
    python) winetricks_do_app python26 ;;
    python-comtypes) winetricks_do_app python26_comtypes ;;
    vbrun60) winetricks_do_app vb6run ;;
    vcrun2005sp1) winetricks_do_app vcrun2005 ;;
    vcrun2008sp1) winetricks_do_app vcrun2008 ;;
    vsm-hard) winetricks_do_app vsm=hardware ;;
    wsh56) winetricks_do_app wsh57 ;;
    xlive) winetricks_do_app gfw ;;

    # Normal verbs, with metadata and load_ functions
    *)
        if winetricks_metadata_exists $1
        then
            winetricks_do_app $1
        else
            echo Unknown arg $1
            winetricks_usage
            exit 1
        fi
        ;;
    esac
}

if ! test "$WINETRICKS_LIB"
then
    winetricks_detect_sudo

    # If user specifies menu on commandline, execute that command, but don't commit to commandline mode
    # FIXME: this code is duplicated several times; unify it
    if echo "$WINETRICKS_CATEGORIES" "$WINETRICKS_COMMANDMENUS" | grep -w "$1" > /dev/null
    then
        WINETRICKS_CURMENU=$1
        shift
    fi

    case "$1" in
    volnameof=*)
        # Debug code.  Remove later?
        # Since linux's volname command can't handle dvds, winetricks has its own,
        # implemented using dd, old gum, and some string I had laying around.
        # You can try it like this:
        #  winetricks volnameof=/dev/sr0
        # or
        #  winetricks volnameof=foo.iso
        # This will read the volname from the given image and put it to stdout.
        winetricks_volname ${1#volnameof=}
        ;;
    "")
        # GUI case
        # No non-option arguments given, so read them from GUI, and loop until user quits
        winetricks_detect_gui
        while true
        do
            case $WINETRICKS_CURMENU in
            main) verbs=`winetricks_mainmenu` ;;
            run) verbs=`winetricks_installed_menu` ;;
            uninstall) verbs=`winetricks_installed_menu` ;;
            settings) verbs=`winetricks_settings_menu` ;;
            *) verbs="`winetricks_showmenu`" ;;
            esac

            if test "$verbs" = ""
            then
                # "user didn't pick anything, back up a level in the menu"
                if test $WINETRICKS_CURMENU = main
                then
                    break
                else
                    WINETRICKS_CURMENU=main
                fi
            elif echo "$WINETRICKS_CATEGORIES" "$WINETRICKS_COMMANDMENUS" | grep -w "$verbs" > /dev/null
            then
                WINETRICKS_CURMENU=$verbs
            else
                winetricks_stats_init
                # Otherwise user picked one or more real verbs.
                for verb in $verbs
                do
                    execute_command $verb
                done
                WINETRICKS_CURMENU=main
            fi
        done
        ;;
    *)
        winetricks_stats_init
        # Commandline case
        # User gave commandline arguments, so just run those verbs and exit
        for verb
        do
            case $verb in
            *.verb)
                # Load the verb file
                case $verb in
                */*) . $verb ;;
                *) . ./$verb ;;
                esac
                # And forget that the verb comes from a file
                verb="`echo $verb | sed 's,.*/,,;s,.verb,,'`"
                ;;
            esac
            execute_command $verb
        done
        ;;

    esac

    winetricks_stats_report
fi
